Created
July 4, 2023 11:23
-
-
Save SelvinPL/29e24a8c72bbd76e2c273582839209dd to your computer and use it in GitHub Desktop.
AggregateUntil
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
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