using System;
using System.Collections.Generic;
namespace ProgrammaticallySpeaking {
public static class ShortCircuit {
public static TAccumulate AggregateUntil(this IEnumerable source, TAccumulate seed, TAccumulate stop, Func func) {
var result = seed;
foreach (var element in source) {
result = func(result, element);
if (result.Equals(stop))
break;
}
return result;
}
}
}
Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/ka732NXWwDk/13671