以下に相当するLINQはありますか?LINQを使用した状態での関数合成からのブレーク
static T Compose<T>(T source,
IEnumerable<Func<T, T>> funcs,
Func<T, bool> cond)
{
foreach (var func in funcs)
{
source = func(source);
if (cond(source)) break;
}
return source;
}
// This ends the composition as soon as a null is returned
var result = Compose(x, funcs, x => x == null);
は基本的に、私は、互いの上に機能を構成し、現在の値が特定の条件に一致する場合に破ることを望みます。
result = f(g(h(x))) // if condition is met somewhere within this chain,
// it will immediately break and return
編集:私は
funcs.Aggregate(seed, (x, f) => cond(x) ? x : f(x));
の線に沿って何かを考えが、それは混乱に見えるとも条件があるとき、コレクション全体にわたり列挙ではなく、壊して終わります会った
関数funcs.Aggregate((cur、next)=>(i => {var val = cur(i); return cond(val)?next(val):val; })) ' – reptile