DavidArno / SuccincT

Discriminated unions, pattern matching and partial applications for C#
MIT License
266 stars 15 forks source link

Make use of C# 7 deconstruct feature to "super charge" IEnumerable<T> cons support #15

Closed DavidArno closed 7 years ago

DavidArno commented 7 years ago

Currently, Succinc<T> can be used to split an IEnumerable<T> into a head and tail via the following method:

var consResult = someEnumeration.ToConsEnumerable().Cons();
// consResult contains Head and Tail

With C# 7 deconstruction though, a simple Deconstruct extension method on IEnumerable<T> would not only allow the above to be written as:

var (head, tail) = someEnumeration;

But also, a deconstruction can be recursive, so to extract the first three items from a list and have tail represent the fourth onwards elements, the code would simply be:

var (head1, (head2, (head3, tail))) = someList;

Modify Succinc<T> to support this.

DavidArno commented 7 years ago

Marking this as a breaking change as I'm removing public static ConsResult<T> Cons<T>(this IEnumerable<T> collection) and replacing it with the deconstruct. ConsResult<T> Cons will still exist for IConsEnumerable though.

DavidArno commented 7 years ago

Included in the v3.0.0 release.