Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
DavidArno opened this issue Jan 5, 2017 · 2 comments

Comments

@DavidArno
Copy link
Owner

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 added a commit that referenced this issue Jan 5, 2017
Added IEnumberable<T> cons suppport via use of C# 7's "tuple deconstruct" feature.
DavidArno added a commit that referenced this issue Jan 5, 2017
…g to get commit in before my train reached its destination! <blush/>)
@DavidArno DavidArno changed the title Make use of C# 7 deconstruct feature to "super charge" IEnmuerable cons support Make use of C# 7 deconstruct feature to "super charge" IEnumerable<T> cons support Jan 5, 2017
@DavidArno DavidArno mentioned this issue Jan 5, 2017
4 tasks
@DavidArno DavidArno added this to the v3.0.0 milestone Feb 2, 2017
@DavidArno DavidArno added the C# 7 label Feb 3, 2017
@DavidArno
Copy link
Owner Author

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 added a commit that referenced this issue Mar 24, 2017
…on<T> and to throw an exception if the collection is empty and so cannot be "cons'ed".

Issue #15
@DavidArno
Copy link
Owner Author

Included in the v3.0.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant