Created
June 21, 2017 20:38
-
-
Save SimonPStevens/382633f5f9e3b55894b6f906319d8a2f to your computer and use it in GitHub Desktop.
A little for each helper to do for each loops either to the end or until a condition is met.
This file contains 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
public static class ForEachHelper | |
{ | |
public static void ForEachUntil<T>(IEnumerable<T> enumerable, Func<T, bool> until, Action<T> loopInner) | |
{ | |
var enumerator = enumerable.GetEnumerator(); | |
while (enumerator.MoveNext() && !until(enumerator.Current)) | |
{ | |
loopInner(enumerator.Current); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment