(line of code of interest is the last one, the rest is just for a full representation)
Using the following code, I wanted to take VOTERS until I exceeded
In a situation where I wanted to execute a function until and including it hit an end condition I did:
public static IEnumerable TakeUntilIncluding(this IEnumerable list, Func predicate)
{
foreach(T el in list)
{
yield return el;
if (predicate(el))
yield break;
}
}
Worked for me! I think this is an implementation-agnostic solution like Jason's, but simpler.