Skip to content

Commit

Permalink
Add implicit ctors
Browse files Browse the repository at this point in the history
Add implicit ctors
  • Loading branch information
Meerow authored Jan 10, 2022
2 parents b837fa7 + d6fec2e commit af1f7bb
Show file tree
Hide file tree
Showing 119 changed files with 4,189 additions and 296 deletions.
17 changes: 13 additions & 4 deletions src/Yaapii.Atoms/Collection/CollectionOf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,20 @@
namespace Yaapii.Atoms.Collection
{
/// <summary>
/// Envelope for collections.
/// It accepts a scalar and makes readonly Collection from it.
/// Collection out of other things.
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class CollectionOf<T> : CollectionEnvelope<T>
{
/// <summary>
/// Makes a collection from an array
/// A collection from an array
/// </summary>
/// <param name="array"></param>
public CollectionOf(params T[] array) : this(new LiveMany<T>(array))
{ }

/// <summary>
/// Makes a collection from an <see cref="IEnumerator{T}"/>
/// A collection from an <see cref="IEnumerator{T}"/>
/// </summary>
/// <param name="src"></param>
public CollectionOf(IEnumerator<T> src) : this(new ManyOf<T>(src))
Expand All @@ -64,4 +63,14 @@ public CollectionOf(IEnumerable<T> src) : base(
)
{ }
}

public static class CollectionOf
{
public static CollectionOf<T> New<T>(params T[] array) => new CollectionOf<T>(array);

public static CollectionOf<T> New<T>(IEnumerator<T> src) => new CollectionOf<T>(src);

public static CollectionOf<T> New<T>(IEnumerable<T> src) => new CollectionOf<T>(src);

}
}
8 changes: 8 additions & 0 deletions src/Yaapii.Atoms/Collection/Filtered.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public Filtered(Func<T, Boolean> func, IEnumerable<T> src) : base(
false
)
{ }


}

public static class Filtered
{
public static Filtered<T> New<T>(Func<T, Boolean> func, IEnumerable<T> src) => new Filtered<T>(func, src);
public static Filtered<T> New<T>(Func<T, Boolean> func, IEnumerator<T> src) => new Filtered<T>(func, src);
public static Filtered<T> New<T>(Func<T, Boolean> func, T item1, T item2, params T[] items) => new Filtered<T>(func, item1, item2, items);
}
}
8 changes: 7 additions & 1 deletion src/Yaapii.Atoms/Collection/HeadOf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace Yaapii.Atoms.Collection
/// <typeparam name="T"></typeparam>
public sealed class HeadOf<T> : CollectionEnvelope<T>
{

/// <summary>
/// ctor
/// </summary>
Expand Down Expand Up @@ -68,6 +67,13 @@ public HeadOf(int lmt, ICollection<T> src) : base(
false
)
{ }
}

public static class HeadOf
{
public static HeadOf<T> New<T>(int lmt, params T[] src) => new HeadOf<T>(lmt, src);
public static HeadOf<T> New<T>(int lmt, ICollection<T> src) => new HeadOf<T>(lmt, src);
public static HeadOf<T> New<T>(int lmt, IEnumerable<T> src) => new HeadOf<T>(lmt, src);
public static HeadOf<T> New<T>(int lmt, IEnumerator<T> src) => new HeadOf<T>(lmt, src);
}
}
4 changes: 4 additions & 0 deletions src/Yaapii.Atoms/Collection/Joined.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public Joined(params IEnumerable<T>[] list) : base(
false
)
{ }
}

public static class Joined
{
public static Joined<T> New<T>(params IEnumerable<T>[] list) => new Joined<T>(list);
}
}
6 changes: 6 additions & 0 deletions src/Yaapii.Atoms/Collection/LiveCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,10 @@ public LiveCollection(IEnumerable<T> src) : base(
)
{ }
}

public static class LiveCollection
{
public static LiveCollection<T> New<T>(IEnumerator<T> src) => new LiveCollection<T>(src);
public static LiveCollection<T> New<T>(IEnumerable<T> src) => new LiveCollection<T>(src);
}
}
20 changes: 20 additions & 0 deletions src/Yaapii.Atoms/Collection/Mapped.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public sealed class Mapped<In, Out> : CollectionEnvelope<Out>
/// <param name="src">source items</param>
public Mapped(Func<In, Out> mapping, params In[] src) : this(mapping, new ManyOf<In>(src))
{ }
public static Mapped<In, Out> New(Func<In, Out> mapping, params In[] src) => new Mapped<In, Out>(mapping, src);

/// <summary>
/// ctor
Expand All @@ -49,6 +50,7 @@ public sealed class Mapped<In, Out> : CollectionEnvelope<Out>
public Mapped(Func<In, Out> mapping, IEnumerator<In> src) : this(
mapping, new ManyOf<In>(src))
{ }
public static Mapped<In, Out> New(Func<In, Out> mapping, IEnumerator<In> src) => new Mapped<In, Out>(mapping, src);

/// <summary>
/// ctor
Expand All @@ -58,6 +60,7 @@ public Mapped(Func<In, Out> mapping, IEnumerator<In> src) : this(
public Mapped(Func<In, Out> mapping, IEnumerable<In> src) : this(
mapping, new LiveCollection<In>(src))
{ }
public static Mapped<In, Out> New(Func<In, Out> mapping, IEnumerable<In> src) => new Mapped<In, Out>(mapping, src);

/// <summary>
/// ctor
Expand All @@ -69,5 +72,22 @@ public Mapped(Func<In, Out> mapping, ICollection<In> src) : base(() =>
false
)
{ }
public static Mapped<In, Out> New(Func<In, Out> mapping, ICollection<In> src) => new Mapped<In, Out>(mapping, src);
}

// <summary>
/// A collection which is mapped to the output type.
/// </summary>
/// <typeparam name="In">source type</typeparam>
/// <typeparam name="Out">target type</typeparam>
public static class Mapped
{
public static Mapped<In, Out> New<In, Out>(Func<In, Out> mapping, params In[] src) => new Mapped<In, Out>(mapping, src);

public static Mapped<In, Out> New<In, Out>(Func<In, Out> mapping, IEnumerator<In> src) => new Mapped<In, Out>(mapping, src);

public static Mapped<In, Out> New<In, Out>(Func<In, Out> mapping, IEnumerable<In> src) => new Mapped<In, Out>(mapping, src);

public static Mapped<In, Out> New<In, Out>(Func<In, Out> mapping, ICollection<In> src) => new Mapped<In, Out>(mapping, src);
}
}
32 changes: 27 additions & 5 deletions src/Yaapii.Atoms/Collection/NotEmpty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,47 @@ public NotEmpty(ICollection<T> origin) : this(
origin,
new Exception("Collection is empty"))
{ }
public static NotEmpty<T> New(ICollection<T> origin) => new NotEmpty<T>(origin);

/// <summary>
/// Ensures that <see cref="ICollection{T}" /> is not empty/>
/// </summary>
/// <param name="origin">Collection</param>
/// <param name="ex">Execption to be thrown if empty</param>
public NotEmpty(ICollection<T> origin, Exception ex) : base(
public NotEmpty(ICollection<T> origin, Exception ex) : this(
origin, () => throw ex
)
{ }

/// <summary>
/// Ensures that <see cref="ICollection{T}" /> is not empty/>
/// </summary>
/// <param name="origin">Collection</param>
/// <param name="ex">Execption to be thrown if empty</param>
public NotEmpty(ICollection<T> origin, Func<ICollection<T>> fallback) : base(
new Live<ICollection<T>>(
() =>
{
new FailPrecise(
new FailEmpty<T>(
origin),
ex).Go();
if (!origin.GetEnumerator().MoveNext())
{
origin = fallback();
}
return origin;
}
),
false
)
{ }
public static NotEmpty<T> New(ICollection<T> origin, Func<ICollection<T>> fallback) => new NotEmpty<T>(origin, fallback);
}

/// <summary>
/// Ensures that <see cref="ICollection{T}" /> is not empty/>
/// </summary>
public static class NotEmpty
{
public static NotEmpty<T> New<T>(ICollection<T> origin) => new NotEmpty<T>(origin);

public static NotEmpty<T> New<T>(ICollection<T> origin, Func<ICollection<T>> fallback) => new NotEmpty<T>(origin, fallback);
}
}
14 changes: 13 additions & 1 deletion src/Yaapii.Atoms/Collection/Reversed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

namespace Yaapii.Atoms.Collection
{
///
/// Reversed collection.
///
/// <para>There is no thread-safety guarantee.</para>
Expand All @@ -39,13 +38,15 @@ public class Reversed<T> : CollectionEnvelope<T>
/// <param name="src"></param>
public Reversed(params T[] src) : this(new ManyOf<T>(src))
{ }
public static Reversed<T> New(params T[] src) => new Reversed<T>(src);

/// <summary>
/// ctor
/// </summary>
/// <param name="src">source collection</param>
public Reversed(IEnumerable<T> src) : this(new LiveCollection<T>(src))
{ }
public static Reversed<T> New(IEnumerable<T> src) => new Reversed<T>(src);

/// <summary>
/// ctor
Expand All @@ -58,5 +59,16 @@ public Reversed(ICollection<T> src) : base(
false
)
{ }
public static Reversed<T> New(ICollection<T> src) => new Reversed<T>(src);
}

/// Reversed collection.
public static class Reversed
{
public static Reversed<T> New<T>(params T[] src) => new Reversed<T>(src);

public static Reversed<T> New<T>(IEnumerable<T> src) => new Reversed<T>(src);

public static Reversed<T> New<T>(ICollection<T> src) => new Reversed<T>(src);
}
}
19 changes: 18 additions & 1 deletion src/Yaapii.Atoms/Collection/Solid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

namespace Yaapii.Atoms.Collection
{
///
/// A <see cref="ICollection{T}"/> that is both synchronized and sticky.
///
/// <para>Objects of this class are thread-safe.</para>
Expand All @@ -38,20 +37,23 @@ public sealed class Solid<T> : CollectionEnvelope<T>
/// <param name="array">source items</param>
public Solid(params T[] array) : this(new LiveMany<T>(array))
{ }
public static Solid<T> New(params T[] array) => new Solid<T>(array);

/// <summary>
/// ctor
/// </summary>
/// <param name="src">source enumerator</param>
public Solid(IEnumerator<T> src) : this(new ManyOf<T>(src))
{ }
public static Solid<T> New(IEnumerator<T> src) => new Solid<T>(src);

/// <summary>
/// ctor
/// </summary>
/// <param name="src">source enumerable</param>
public Solid(IEnumerable<T> src) : this(new LiveCollection<T>(src))
{ }
public static Solid<T> New(IEnumerable<T> src) => new Solid<T>(src);

/// <summary>
/// ctor
Expand All @@ -65,6 +67,21 @@ public Solid(ICollection<T> src) : base(
false
)
{ }
public static Solid<T> New(ICollection<T> src) => new Solid<T>(src);
}

/// A <see cref="ICollection{T}"/> that is both synchronized and sticky.
///
/// <para>Objects of this class are thread-safe.</para>
///
public static class Solid
{
public static Solid<T> New<T>(params T[] array) => new Solid<T>(array);

public static Solid<T> New<T>(IEnumerator<T> src) => new Solid<T>(src);

public static Solid<T> New<T>(IEnumerable<T> src) => new Solid<T>(src);

public static Solid<T> New<T>(ICollection<T> src) => new Solid<T>(src);
}
}
14 changes: 14 additions & 0 deletions src/Yaapii.Atoms/Collection/Sorted.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,18 @@ public Sorted(Comparer<T> cmp, ICollection<T> src) : base(
)
{ }
}

public static class Sorted
{
/// <summary>
public static Sorted<T> New<T>(params T[] src) where T : IComparable<T> => new Sorted<T>(src);

public static Sorted<T> New<T>(IEnumerable<T> src) where T : IComparable<T> => new Sorted<T>(src);

public static Sorted<T> New<T>(Comparer<T> cmp, params T[] src) where T : IComparable<T> => new Sorted<T>(cmp, src);

public static Sorted<T> New<T>(Comparer<T> cmp, IEnumerator<T> src) where T : IComparable<T> => new Sorted<T>(cmp, src);

public static Sorted<T> New<T>(Comparer<T> cmp, ICollection<T> src) where T : IComparable<T> => new Sorted<T>(cmp, src);
}
}
5 changes: 5 additions & 0 deletions src/Yaapii.Atoms/Collection/Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@ public Sync(object syncRoot, ICollection<T> col) : base(
)
{ }
}

public static class Sync
{
public static Sync<T> New<T>(params T[] items) => new Sync<T>(items);
}
}
30 changes: 14 additions & 16 deletions src/Yaapii.Atoms/Enumerable/Contains.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ namespace Yaapii.Atoms.Enumerable
/// Lookup if an item is in a enumerable.
/// </summary>
/// <typeparam name="T"></typeparam>
public class Contains<T> : IScalar<bool>
public sealed class Contains<T> : ScalarEnvelope<bool>
{
private readonly ScalarOf<bool> result;

/// <summary>
/// Lookup if an item is in a enumerable by calling .Equals(...) of the item.
/// </summary>
Expand All @@ -49,19 +47,19 @@ public Contains(IEnumerable<T> src, T item) : this(
/// </summary>
/// <param name="items">enumerable to search through</param>
/// <param name="match">check to perform on each item</param>
public Contains(IEnumerable<T> items, Func<T, bool> match)
{
this.result =
new ScalarOf<bool>(() => new Enumerator.Contains<T>(items.GetEnumerator(), match).Value());
}
public Contains(IEnumerable<T> items, Func<T, bool> match) : base(() =>
new Enumerator.Contains<T>(items.GetEnumerator(), match).Value())
{ }
}

/// <summary>
/// see if the item is in the enumerable.
/// </summary>
/// <returns>true if item is in the enumerable</returns>
public bool Value()
{
return this.result.Value();
}
/// <summary>
/// Lookup if an item is in a enumerable.
/// </summary>
/// <typeparam name="T"></typeparam>
public static class Contains
{
public static Contains<T> New<T>(IEnumerable<T> src, T item) => new Contains<T>(src, item);

public static Contains<T> New<T>(IEnumerable<T> items, Func<T, bool> match) => new Contains<T>(items, match);
}
}
13 changes: 9 additions & 4 deletions src/Yaapii.Atoms/Enumerable/Cycled.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

using System.Collections.Generic;

#pragma warning disable NoGetOrSet // No Statics
#pragma warning disable CS1591

namespace Yaapii.Atoms.Enumerable
{
/// <summary>
Expand All @@ -45,5 +42,13 @@ public Cycled(IEnumerable<T> enumerable) : base(() =>
)
{ }
}

/// <summary>
/// A <see cref="IEnumerable{T}"/> that starts from the beginning when ended.
/// </summary>
/// <typeparam name="T">type of the contents</typeparam>
public static class Cycled
{
public static Cycled<T> New<T>(IEnumerable<T> enumerable) => new Cycled<T>(enumerable);
}
}
#pragma warning restore NoGetOrSet // No Statics
Loading

0 comments on commit af1f7bb

Please sign in to comment.