Skip to content

Instantly share code, notes, and snippets.

@SelvinPL
Created July 4, 2023 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SelvinPL/29e24a8c72bbd76e2c273582839209dd to your computer and use it in GitHub Desktop.
Save SelvinPL/29e24a8c72bbd76e2c273582839209dd to your computer and use it in GitHub Desktop.
AggregateUntil
static class Ext
{
public static TAccumulate AggregateUntil<TSource, TAccumulate>(this IEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, (bool, TAccumulate)> func)
{
foreach(var item in source)
{
var res = func(seed, item);
seed = res.Item2;
if(res.Item1)
break;
}
return seed;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment