Skip to content

Commit

Permalink
Seq1 to Seq
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Louth committed Oct 20, 2021
1 parent 1324875 commit 6e9c4fd
Show file tree
Hide file tree
Showing 111 changed files with 556 additions and 387 deletions.
2 changes: 1 addition & 1 deletion LanguageExt.Benchmarks/ListIterationBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void Setup()
values = ValuesGenerator.Default.GenerateUniqueValues<T>(N);
immutableList = ImmutableList.CreateRange(ValuesGenerator.Default.GenerateUniqueValues<T>(N));
lst = ValuesGenerator.Default.GenerateUniqueValues<T>(N).Freeze();
seq = Seq(ValuesGenerator.Default.GenerateUniqueValues<T>(N)).Strict();
seq = toSeq(ValuesGenerator.Default.GenerateUniqueValues<T>(N)).Strict();
}

[Benchmark]
Expand Down
4 changes: 2 additions & 2 deletions LanguageExt.Core/ClassInstances/Monad/MValidationSeq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ err switch
{
// Messy, but we're doing our best to recover an error rather than return Bottom

FAIL fail => Validation<FAIL, SUCCESS>.Fail(Seq1(fail)),
FAIL fail => Validation<FAIL, SUCCESS>.Fail(Seq(fail)),
Seq<FAIL> fails => Validation<FAIL, SUCCESS>.Fail(fails),
_ => Common.Error
.Convert<FAIL>(err)
.Map(f => Validation<FAIL, SUCCESS>.Fail(Seq1(f)))
.Map(f => Validation<FAIL, SUCCESS>.Fail(Seq(f)))
.IfNone(Validation<FAIL, SUCCESS>.Fail(Seq<FAIL>.Empty))
};

Expand Down
2 changes: 1 addition & 1 deletion LanguageExt.Core/ClassInstances/Monoid/MCompositions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public Compositions<A> Append(Compositions<A> compx, Compositions<A> compy)
Seq<Compositions<A>.Node> go(Seq<Compositions<A>.Node> mx, Seq<Compositions<A>.Node> my)
{
if (mx.IsEmpty) return my;
if (my.IsEmpty) return go(mx.Tail, Seq1(mx.Head));
if (my.IsEmpty) return go(mx.Tail, Seq(mx.Head));

var x = mx.Head;
var sx = mx.Head.Size;
Expand Down
6 changes: 3 additions & 3 deletions LanguageExt.Core/Concurrency/AtomSeq/AtomSeq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public Unit Add(A value)
Arr<A> arr => Concat(arr),
Stck<A> stck => Concat(stck),
IReadOnlyList<A> rolist => Concat(rolist),
_ => Concat(Seq(items))
_ => Concat(toSeq(items))
};

/// <summary>
Expand Down Expand Up @@ -541,7 +541,7 @@ public Option<A> LastOrNone()
{
var xs = items;
return xs.IsEmpty
? Validation<F, A>.Fail(Seq1(Fail))
? Validation<F, A>.Fail(Seq(Fail))
: Validation<F, A>.Success(xs.Last);
}

Expand All @@ -554,7 +554,7 @@ public Option<A> LastOrNone()
{
var xs = items;
return xs.IsEmpty
? Validation<F, A>.Fail(Seq1(Fail()))
? Validation<F, A>.Fail(Seq(Fail()))
: Validation<F, A>.Success(xs.Last);
}

Expand Down
4 changes: 2 additions & 2 deletions LanguageExt.Core/Concurrency/VectorClock/VectorClock.A.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public record VectorClock<A>(Seq<(A, long)> Entries)
/// A vector clock with a single element
/// </summary>
public static VectorClock<A> Single(A x, long y) =>
fromList(Seq1((x, y)));
fromList(Seq((x, y)));

/// <summary>
/// Insert each entry in the list one at a time.
Expand Down Expand Up @@ -164,7 +164,7 @@ public VectorClock<A> Insert(A index, long value)

Seq<(A, long)> go(Seq<(A, long)> entries) =>
entries.IsEmpty
? Seq1((index, value))
? Seq((index, value))
: entries.Head switch
{
(var x1, _) xy when lessThan<OrdDefault<A>, A>(x1, index) => xy.Cons(go(entries.Tail)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public record VectorClock<OrdA, NumB, A, B>(Seq<(A, B)> Entries)
/// A vector clock with a single element
/// </summary>
public static VectorClock<OrdA, NumB, A, B> Single(A x, B y) =>
fromList(Seq1((x, y)));
fromList(Seq((x, y)));

/// <summary>
/// Insert each entry in the list one at a time.
Expand Down Expand Up @@ -169,7 +169,7 @@ public Option<B> Lookup(A index)

Seq<(A, B)> go(Seq<(A, B)> entries) =>
entries.IsEmpty
? Seq1((index, value))
? Seq((index, value))
: entries.Head switch
{
(var x1, _) xy when lessThan<OrdA, A>(x1, index) => xy.Cons(go(entries.Tail)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public IEnumerable<V> Values
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Seq<(K Key, V Value)> ToSeq() =>
Seq(AsEnumerable());
toSeq(AsEnumerable());

/// <summary>
/// Format the collection as `[(key: value), (key: value), (key: value), ...]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)

[Pure]
public Seq<L> ToSeq() =>
Seq1(Value);
Seq(Value);

[Pure]
public IEnumerable<L> AsEnumerable() =>
Seq1(Value).AsEnumerable();
Seq(Value).AsEnumerable();

[Pure]
public EitherUnsafe<L, R> ToEitherUnsafe<R>() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)

[Pure]
public Seq<R> ToSeq() =>
Seq1(Value);
Seq(Value);

[Pure]
public IEnumerable<R> AsEnumerable() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ public async Task<Unit> MatchAsync(Func<R, Task> RightAsync, Func<L, Task> LeftA
[Pure]
public Task<Seq<R>> RightAsEnumerable() =>
Match(
Right: r => Seq1(r),
Right: r => Seq(r),
Left: l => Seq<R>.Empty,
Bottom: () => Seq<R>.Empty);

Expand All @@ -833,7 +833,7 @@ public async Task<Unit> MatchAsync(Func<R, Task> RightAsync, Func<L, Task> LeftA
public Task<Seq<L>> LeftAsEnumerable() =>
Match(
Right: r => Seq<L>.Empty,
Left: l => Seq1(l),
Left: l => Seq(l),
Bottom: () => Seq<L>.Empty);

[Pure]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ public Fin<A> Do(Action<A> Succ)
[Pure, MethodImpl(Opt.Default)]
public Seq<A> ToSeq() =>
IsSucc
? Seq1(Value)
? Seq(Value)
: Empty;

[Pure, MethodImpl(Opt.Default)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static class NullableExtensions
/// <returns>Zero or One values, depending on HasValue</returns>
[Pure]
public static Seq<A> ToSeq<A>(this A? self) where A : struct =>
Seq(self);
toSeq(self);

/// <summary>
/// Convert NullableT to IEnumerableT (0..1 entries)
Expand All @@ -43,7 +43,7 @@ public static class NullableExtensions
/// <returns>Zero or One enumerable values, depending on HasValue</returns>
[Pure]
public static Seq<T> AsEnumerable<T>(this T? self) where T : struct =>
Seq(self);
toSeq(self);

/// <summary>
/// Match the two states of the Nullable and return a non-null R.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ IEnumerable<A> ToSequence(Seq<Option<A>> items)
}
}
}
return Seq(ToSequence(self));
return toSeq(ToSequence(self));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public Option<A> Do(Action<A> f)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Seq<A> ToSeq() =>
isSome
? Seq1(Value)
? Seq(Value)
: Empty;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ IEnumerable<A> ToSequence(Seq<OptionUnsafe<A>> items)
}
}
}
return Seq(ToSequence(self));
return toSeq(ToSequence(self));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ public OptionUnsafe<A> Do(Action<A> f)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Seq<A> ToSeq() =>
isSome
? Seq1(Value)
? Seq(Value)
: Empty;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Some(IEnumerable<A> someValue)
[Pure]
public Seq<A> ToSeq() =>
initialised
? Seq1(value)
? Seq(value)
: Empty;

[Pure]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static partial class Prelude
/// <param name="value">Error value</param>
/// <returns>Validation applicative</returns>
public static Validation<ERROR, A> Fail<ERROR, A>(ERROR value) =>
Validation<ERROR, A>.Fail(Seq1(value));
Validation<ERROR, A>.Fail(Seq(value));

/// <summary>
/// Represents a failed operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace LanguageExt
/// </summary>
public Validation(IEnumerable<ValidationData<MonoidFail, FAIL, SUCCESS>> validationData)
{
var seq = Seq(validationData);
var seq = toSeq(validationData);
if (seq.IsEmpty)
{
this.state = Validation.StateType.Fail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static class ValidationSeqExtensions
/// <returns>Enumerable of successes</returns>
[Pure]
public static Seq<S> Successes<F, S>(this Seq<Validation<F, S>> vs) =>
Seq(Successes(vs.AsEnumerable()));
toSeq(Successes(vs.AsEnumerable()));

/// <summary>
/// Extract only the failures
Expand All @@ -81,7 +81,7 @@ public static class ValidationSeqExtensions
/// <returns>Enumerable of failures</returns>
[Pure]
public static Seq<F> Fails<F, S>(this Seq<Validation<F, S>> vs) =>
Seq(Fails(vs.AsEnumerable()));
toSeq(Fails(vs.AsEnumerable()));

/// <summary>
/// Extract only the successes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ namespace LanguageExt
[Pure]
public Validation(IEnumerable<ValidationData<FAIL, SUCCESS>> validationData)
{
var seq = Seq(validationData);
var seq = toSeq(validationData);
if (seq.IsEmpty)
{
this.state = Validation.StateType.Fail;
Expand Down Expand Up @@ -192,7 +192,7 @@ state switch
public static implicit operator Validation<FAIL, SUCCESS>(FAIL value) =>
isnull(value)
? throw new ValueIsNullException()
: Fail(Seq1(value));
: Fail(Seq(value));

[Pure]
public Validation<FAIL, SUCCESS> Disjunction<SUCCESSB>(Validation<FAIL, SUCCESSB> other)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Seq<Compositions<A>.Node> go(int n, Seq<Compositions<A>.Node> nodes)
else
{
return default(MCompositions<MonoidA, A>)
.Append(new Compositions<A>(Seq1(x)), new Compositions<A>(go(n - s, ri)))
.Append(new Compositions<A>(Seq(x)), new Compositions<A>(go(n - s, ri)))
.Tree;
}
}
Expand Down Expand Up @@ -148,7 +148,7 @@ public static (Compositions<A> taken, Compositions<A> skipped) splitAt<MonoidA,
/// Construct a compositions list containing just one element.
/// </summary>
public static Compositions<A> singleton<A>(A value) =>
new Compositions<A>(Seq1(new Compositions<A>.Node(1, None, value)));
new Compositions<A>(Seq(new Compositions<A>.Node(1, None, value)));

/// <summary>
/// Get the number of elements in the compositions list, in `O(log n)` time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public Arr<A> SetItem(int index, A value)
[Pure]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Seq<A> ToSeq() =>
Seq(this);
toSeq(this);

/// <summary>
/// Format the collection as `[a, b, c, ...]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public BiMap(IEnumerable<(A Left, B Right)> items) : this(items, true)

[Pure]
public Seq<(A Key, B Value)> ToSeq() =>
Prelude.Seq(this);
Prelude.toSeq(this);

[Pure]
public bool Equals(BiMap<A, B> y) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ IEnumerable<A> Yield(TrieSet<EqA, A> map, Func<A, bool> f)

[Pure]
public Seq<A> ToSeq() =>
Prelude.Seq(this);
toSeq(this);

/// <summary>
/// Format the collection as `[a, b, c, ...]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ IEnumerable<A> Yield(TrieSet<EqDefault<A>, A> map, Func<A, bool> f)

[Pure]
public Seq<A> ToSeq() =>
Prelude.Seq(this);
toSeq(this);

/// <summary>
/// Format the collection as `[a, b, c, ...]`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ public static class ListExtensions
/// Converts an enumerable to a `Seq`
/// </summary>
public static Seq<A> ToSeq<A>(this IEnumerable<A> enumerable) =>
Seq(enumerable);
toSeq(enumerable);

/// <summary>
/// Converts an enumerable to a `Seq`
/// </summary>
public static Seq<A> ToSeq<A>(this IList<A> enumerable) =>
Seq(enumerable);
toSeq(enumerable);

/// <summary>
/// Converts an array to a `Seq`
/// </summary>
public static Seq<A> ToSeq<A>(this A[] array) =>
Seq(array);
toSeq(array);

/// <summary>
/// Concatenate two enumerables (Concat in LINQ)
Expand All @@ -64,7 +64,7 @@ public static class ListExtensions
public static B Match<A, B>(this IEnumerable<A> list,
Func<B> Empty,
Func<Seq<A>, B> More) =>
Seq(list).Match(Empty, More);
toSeq(list).Match(Empty, More);

/// <summary>
/// List pattern matching
Expand All @@ -73,7 +73,7 @@ public static class ListExtensions
public static B Match<A, B>(this IEnumerable<A> list,
Func<B> Empty,
Func<A, Seq<A>, B> More) =>
Seq(list).Match(Empty, More);
toSeq(list).Match(Empty, More);

/// <summary>
/// List pattern matching
Expand All @@ -83,7 +83,7 @@ public static class ListExtensions
Func<R> Empty,
Func<T, R> One,
Func<T, Seq<T>, R> More ) =>
Seq(list).Match(Empty, One, More);
toSeq(list).Match(Empty, One, More);

/// <summary>
/// Get the item at the head (first) of the list
Expand Down Expand Up @@ -177,7 +177,7 @@ public static class ListExtensions
[Pure]
public static Validation<Fail, Success> LastOrInvalid<Fail, Success>(this IEnumerable<Success> list, Fail fail) =>
list.Select(Validation<Fail, Success>.Success)
.DefaultIfEmpty(Validation<Fail, Success>.Fail(Seq1(fail)))
.DefaultIfEmpty(Validation<Fail, Success>.Fail(Seq(fail)))
.LastOrDefault();

/// <summary>
Expand Down
Loading

0 comments on commit 6e9c4fd

Please sign in to comment.