Skip to content

Commit af1f7bb

Browse files
author
Meerow
authored
Add implicit ctors
Add implicit ctors
2 parents b837fa7 + d6fec2e commit af1f7bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+4189
-296
lines changed

src/Yaapii.Atoms/Collection/CollectionOf.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,20 @@
2626
namespace Yaapii.Atoms.Collection
2727
{
2828
/// <summary>
29-
/// Envelope for collections.
30-
/// It accepts a scalar and makes readonly Collection from it.
29+
/// Collection out of other things.
3130
/// </summary>
3231
/// <typeparam name="T"></typeparam>
3332
public sealed class CollectionOf<T> : CollectionEnvelope<T>
3433
{
3534
/// <summary>
36-
/// Makes a collection from an array
35+
/// A collection from an array
3736
/// </summary>
3837
/// <param name="array"></param>
3938
public CollectionOf(params T[] array) : this(new LiveMany<T>(array))
4039
{ }
4140

4241
/// <summary>
43-
/// Makes a collection from an <see cref="IEnumerator{T}"/>
42+
/// A collection from an <see cref="IEnumerator{T}"/>
4443
/// </summary>
4544
/// <param name="src"></param>
4645
public CollectionOf(IEnumerator<T> src) : this(new ManyOf<T>(src))
@@ -64,4 +63,14 @@ public CollectionOf(IEnumerable<T> src) : base(
6463
)
6564
{ }
6665
}
66+
67+
public static class CollectionOf
68+
{
69+
public static CollectionOf<T> New<T>(params T[] array) => new CollectionOf<T>(array);
70+
71+
public static CollectionOf<T> New<T>(IEnumerator<T> src) => new CollectionOf<T>(src);
72+
73+
public static CollectionOf<T> New<T>(IEnumerable<T> src) => new CollectionOf<T>(src);
74+
75+
}
6776
}

src/Yaapii.Atoms/Collection/Filtered.cs

+8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@ public Filtered(Func<T, Boolean> func, IEnumerable<T> src) : base(
7979
false
8080
)
8181
{ }
82+
8283

8384
}
85+
86+
public static class Filtered
87+
{
88+
public static Filtered<T> New<T>(Func<T, Boolean> func, IEnumerable<T> src) => new Filtered<T>(func, src);
89+
public static Filtered<T> New<T>(Func<T, Boolean> func, IEnumerator<T> src) => new Filtered<T>(func, src);
90+
public static Filtered<T> New<T>(Func<T, Boolean> func, T item1, T item2, params T[] items) => new Filtered<T>(func, item1, item2, items);
91+
}
8492
}

src/Yaapii.Atoms/Collection/HeadOf.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ namespace Yaapii.Atoms.Collection
3131
/// <typeparam name="T"></typeparam>
3232
public sealed class HeadOf<T> : CollectionEnvelope<T>
3333
{
34-
3534
/// <summary>
3635
/// ctor
3736
/// </summary>
@@ -68,6 +67,13 @@ public HeadOf(int lmt, ICollection<T> src) : base(
6867
false
6968
)
7069
{ }
70+
}
7171

72+
public static class HeadOf
73+
{
74+
public static HeadOf<T> New<T>(int lmt, params T[] src) => new HeadOf<T>(lmt, src);
75+
public static HeadOf<T> New<T>(int lmt, ICollection<T> src) => new HeadOf<T>(lmt, src);
76+
public static HeadOf<T> New<T>(int lmt, IEnumerable<T> src) => new HeadOf<T>(lmt, src);
77+
public static HeadOf<T> New<T>(int lmt, IEnumerator<T> src) => new HeadOf<T>(lmt, src);
7278
}
7379
}

src/Yaapii.Atoms/Collection/Joined.cs

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public Joined(params IEnumerable<T>[] list) : base(
4141
false
4242
)
4343
{ }
44+
}
4445

46+
public static class Joined
47+
{
48+
public static Joined<T> New<T>(params IEnumerable<T>[] list) => new Joined<T>(list);
4549
}
4650
}

src/Yaapii.Atoms/Collection/LiveCollection.cs

+6
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,10 @@ public LiveCollection(IEnumerable<T> src) : base(
5656
)
5757
{ }
5858
}
59+
60+
public static class LiveCollection
61+
{
62+
public static LiveCollection<T> New<T>(IEnumerator<T> src) => new LiveCollection<T>(src);
63+
public static LiveCollection<T> New<T>(IEnumerable<T> src) => new LiveCollection<T>(src);
64+
}
5965
}

src/Yaapii.Atoms/Collection/Mapped.cs

+20
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public sealed class Mapped<In, Out> : CollectionEnvelope<Out>
4040
/// <param name="src">source items</param>
4141
public Mapped(Func<In, Out> mapping, params In[] src) : this(mapping, new ManyOf<In>(src))
4242
{ }
43+
public static Mapped<In, Out> New(Func<In, Out> mapping, params In[] src) => new Mapped<In, Out>(mapping, src);
4344

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

5355
/// <summary>
5456
/// ctor
@@ -58,6 +60,7 @@ public Mapped(Func<In, Out> mapping, IEnumerator<In> src) : this(
5860
public Mapped(Func<In, Out> mapping, IEnumerable<In> src) : this(
5961
mapping, new LiveCollection<In>(src))
6062
{ }
63+
public static Mapped<In, Out> New(Func<In, Out> mapping, IEnumerable<In> src) => new Mapped<In, Out>(mapping, src);
6164

6265
/// <summary>
6366
/// ctor
@@ -69,5 +72,22 @@ public Mapped(Func<In, Out> mapping, ICollection<In> src) : base(() =>
6972
false
7073
)
7174
{ }
75+
public static Mapped<In, Out> New(Func<In, Out> mapping, ICollection<In> src) => new Mapped<In, Out>(mapping, src);
76+
}
77+
78+
// <summary>
79+
/// A collection which is mapped to the output type.
80+
/// </summary>
81+
/// <typeparam name="In">source type</typeparam>
82+
/// <typeparam name="Out">target type</typeparam>
83+
public static class Mapped
84+
{
85+
public static Mapped<In, Out> New<In, Out>(Func<In, Out> mapping, params In[] src) => new Mapped<In, Out>(mapping, src);
86+
87+
public static Mapped<In, Out> New<In, Out>(Func<In, Out> mapping, IEnumerator<In> src) => new Mapped<In, Out>(mapping, src);
88+
89+
public static Mapped<In, Out> New<In, Out>(Func<In, Out> mapping, IEnumerable<In> src) => new Mapped<In, Out>(mapping, src);
90+
91+
public static Mapped<In, Out> New<In, Out>(Func<In, Out> mapping, ICollection<In> src) => new Mapped<In, Out>(mapping, src);
7292
}
7393
}

src/Yaapii.Atoms/Collection/NotEmpty.cs

+27-5
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,47 @@ public NotEmpty(ICollection<T> origin) : this(
4141
origin,
4242
new Exception("Collection is empty"))
4343
{ }
44+
public static NotEmpty<T> New(ICollection<T> origin) => new NotEmpty<T>(origin);
4445

4546
/// <summary>
4647
/// Ensures that <see cref="ICollection{T}" /> is not empty/>
4748
/// </summary>
4849
/// <param name="origin">Collection</param>
4950
/// <param name="ex">Execption to be thrown if empty</param>
50-
public NotEmpty(ICollection<T> origin, Exception ex) : base(
51+
public NotEmpty(ICollection<T> origin, Exception ex) : this(
52+
origin, () => throw ex
53+
)
54+
{ }
55+
56+
/// <summary>
57+
/// Ensures that <see cref="ICollection{T}" /> is not empty/>
58+
/// </summary>
59+
/// <param name="origin">Collection</param>
60+
/// <param name="ex">Execption to be thrown if empty</param>
61+
public NotEmpty(ICollection<T> origin, Func<ICollection<T>> fallback) : base(
5162
new Live<ICollection<T>>(
5263
() =>
5364
{
54-
new FailPrecise(
55-
new FailEmpty<T>(
56-
origin),
57-
ex).Go();
65+
if (!origin.GetEnumerator().MoveNext())
66+
{
67+
origin = fallback();
68+
}
5869
return origin;
5970
}
6071
),
6172
false
6273
)
6374
{ }
75+
public static NotEmpty<T> New(ICollection<T> origin, Func<ICollection<T>> fallback) => new NotEmpty<T>(origin, fallback);
76+
}
77+
78+
/// <summary>
79+
/// Ensures that <see cref="ICollection{T}" /> is not empty/>
80+
/// </summary>
81+
public static class NotEmpty
82+
{
83+
public static NotEmpty<T> New<T>(ICollection<T> origin) => new NotEmpty<T>(origin);
84+
85+
public static NotEmpty<T> New<T>(ICollection<T> origin, Func<ICollection<T>> fallback) => new NotEmpty<T>(origin, fallback);
6486
}
6587
}

src/Yaapii.Atoms/Collection/Reversed.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
namespace Yaapii.Atoms.Collection
2828
{
29-
///
3029
/// Reversed collection.
3130
///
3231
/// <para>There is no thread-safety guarantee.</para>
@@ -39,13 +38,15 @@ public class Reversed<T> : CollectionEnvelope<T>
3938
/// <param name="src"></param>
4039
public Reversed(params T[] src) : this(new ManyOf<T>(src))
4140
{ }
41+
public static Reversed<T> New(params T[] src) => new Reversed<T>(src);
4242

4343
/// <summary>
4444
/// ctor
4545
/// </summary>
4646
/// <param name="src">source collection</param>
4747
public Reversed(IEnumerable<T> src) : this(new LiveCollection<T>(src))
4848
{ }
49+
public static Reversed<T> New(IEnumerable<T> src) => new Reversed<T>(src);
4950

5051
/// <summary>
5152
/// ctor
@@ -58,5 +59,16 @@ public Reversed(ICollection<T> src) : base(
5859
false
5960
)
6061
{ }
62+
public static Reversed<T> New(ICollection<T> src) => new Reversed<T>(src);
63+
}
64+
65+
/// Reversed collection.
66+
public static class Reversed
67+
{
68+
public static Reversed<T> New<T>(params T[] src) => new Reversed<T>(src);
69+
70+
public static Reversed<T> New<T>(IEnumerable<T> src) => new Reversed<T>(src);
71+
72+
public static Reversed<T> New<T>(ICollection<T> src) => new Reversed<T>(src);
6173
}
6274
}

src/Yaapii.Atoms/Collection/Solid.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

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

4242
/// <summary>
4343
/// ctor
4444
/// </summary>
4545
/// <param name="src">source enumerator</param>
4646
public Solid(IEnumerator<T> src) : this(new ManyOf<T>(src))
4747
{ }
48+
public static Solid<T> New(IEnumerator<T> src) => new Solid<T>(src);
4849

4950
/// <summary>
5051
/// ctor
5152
/// </summary>
5253
/// <param name="src">source enumerable</param>
5354
public Solid(IEnumerable<T> src) : this(new LiveCollection<T>(src))
5455
{ }
56+
public static Solid<T> New(IEnumerable<T> src) => new Solid<T>(src);
5557

5658
/// <summary>
5759
/// ctor
@@ -65,6 +67,21 @@ public Solid(ICollection<T> src) : base(
6567
false
6668
)
6769
{ }
70+
public static Solid<T> New(ICollection<T> src) => new Solid<T>(src);
71+
}
72+
73+
/// A <see cref="ICollection{T}"/> that is both synchronized and sticky.
74+
///
75+
/// <para>Objects of this class are thread-safe.</para>
76+
///
77+
public static class Solid
78+
{
79+
public static Solid<T> New<T>(params T[] array) => new Solid<T>(array);
80+
81+
public static Solid<T> New<T>(IEnumerator<T> src) => new Solid<T>(src);
82+
83+
public static Solid<T> New<T>(IEnumerable<T> src) => new Solid<T>(src);
6884

85+
public static Solid<T> New<T>(ICollection<T> src) => new Solid<T>(src);
6986
}
7087
}

src/Yaapii.Atoms/Collection/Sorted.cs

+14
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,18 @@ public Sorted(Comparer<T> cmp, ICollection<T> src) : base(
8787
)
8888
{ }
8989
}
90+
91+
public static class Sorted
92+
{
93+
/// <summary>
94+
public static Sorted<T> New<T>(params T[] src) where T : IComparable<T> => new Sorted<T>(src);
95+
96+
public static Sorted<T> New<T>(IEnumerable<T> src) where T : IComparable<T> => new Sorted<T>(src);
97+
98+
public static Sorted<T> New<T>(Comparer<T> cmp, params T[] src) where T : IComparable<T> => new Sorted<T>(cmp, src);
99+
100+
public static Sorted<T> New<T>(Comparer<T> cmp, IEnumerator<T> src) where T : IComparable<T> => new Sorted<T>(cmp, src);
101+
102+
public static Sorted<T> New<T>(Comparer<T> cmp, ICollection<T> src) where T : IComparable<T> => new Sorted<T>(cmp, src);
103+
}
90104
}

src/Yaapii.Atoms/Collection/Sync.cs

+5
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,9 @@ public Sync(object syncRoot, ICollection<T> col) : base(
8383
)
8484
{ }
8585
}
86+
87+
public static class Sync
88+
{
89+
public static Sync<T> New<T>(params T[] items) => new Sync<T>(items);
90+
}
8691
}

src/Yaapii.Atoms/Enumerable/Contains.cs

+14-16
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ namespace Yaapii.Atoms.Enumerable
3030
/// Lookup if an item is in a enumerable.
3131
/// </summary>
3232
/// <typeparam name="T"></typeparam>
33-
public class Contains<T> : IScalar<bool>
33+
public sealed class Contains<T> : ScalarEnvelope<bool>
3434
{
35-
private readonly ScalarOf<bool> result;
36-
3735
/// <summary>
3836
/// Lookup if an item is in a enumerable by calling .Equals(...) of the item.
3937
/// </summary>
@@ -49,19 +47,19 @@ public Contains(IEnumerable<T> src, T item) : this(
4947
/// </summary>
5048
/// <param name="items">enumerable to search through</param>
5149
/// <param name="match">check to perform on each item</param>
52-
public Contains(IEnumerable<T> items, Func<T, bool> match)
53-
{
54-
this.result =
55-
new ScalarOf<bool>(() => new Enumerator.Contains<T>(items.GetEnumerator(), match).Value());
56-
}
50+
public Contains(IEnumerable<T> items, Func<T, bool> match) : base(() =>
51+
new Enumerator.Contains<T>(items.GetEnumerator(), match).Value())
52+
{ }
53+
}
5754

58-
/// <summary>
59-
/// see if the item is in the enumerable.
60-
/// </summary>
61-
/// <returns>true if item is in the enumerable</returns>
62-
public bool Value()
63-
{
64-
return this.result.Value();
65-
}
55+
/// <summary>
56+
/// Lookup if an item is in a enumerable.
57+
/// </summary>
58+
/// <typeparam name="T"></typeparam>
59+
public static class Contains
60+
{
61+
public static Contains<T> New<T>(IEnumerable<T> src, T item) => new Contains<T>(src, item);
62+
63+
public static Contains<T> New<T>(IEnumerable<T> items, Func<T, bool> match) => new Contains<T>(items, match);
6664
}
6765
}

src/Yaapii.Atoms/Enumerable/Cycled.cs

+9-4
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222

2323
using System.Collections.Generic;
2424

25-
#pragma warning disable NoGetOrSet // No Statics
26-
#pragma warning disable CS1591
27-
2825
namespace Yaapii.Atoms.Enumerable
2926
{
3027
/// <summary>
@@ -45,5 +42,13 @@ public Cycled(IEnumerable<T> enumerable) : base(() =>
4542
)
4643
{ }
4744
}
45+
46+
/// <summary>
47+
/// A <see cref="IEnumerable{T}"/> that starts from the beginning when ended.
48+
/// </summary>
49+
/// <typeparam name="T">type of the contents</typeparam>
50+
public static class Cycled
51+
{
52+
public static Cycled<T> New<T>(IEnumerable<T> enumerable) => new Cycled<T>(enumerable);
53+
}
4854
}
49-
#pragma warning restore NoGetOrSet // No Statics

0 commit comments

Comments
 (0)