Last active
September 9, 2019 03:16
-
-
Save imgen/00a240946733de45bbc7c140817b0fc9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
public static class EnumeratorExtensions | |
{ | |
public static IEnumerable<T> TakeNextUntil<T>(this IEnumerator<T> enumerator, Predicate<T> predicate) | |
{ | |
while(enumerator.MoveNext()) | |
{ | |
var item = enumerator.Current; | |
if (predicate(item)) | |
break; | |
yield return item; | |
} | |
} | |
public static T TakeNextItem<T>(this IEnumerator<T> enumerator) => | |
enumerator.MoveNext()? enumerator.Current : throw new Exception("Cannot retrieve next item"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment