Method AggregateOrNone
- Namespace
- SodaFlow.Functional
- Assembly
- SodaFlow.Functional.dll
AggregateOrNone<T>(IEnumerable<T>?, Func<T, T, T>)
Combines the elements of a sequence with a function, if it has any.
[Pure]
public static Maybe<T> AggregateOrNone<T>(this IEnumerable<T>? source, Func<T, T, T> f)
Parameters
sourceIEnumerable<T>The sequence to fold. A null sequence counts as empty.
fFunc<T, T, T>Applied to the result so far and the next element, starting with the first two elements.
Returns
- Maybe<T>
A Maybe<T> containing the combined value, the single element if there was only one, and no value if the sequence was empty.
Type Parameters
TThe type of the values in the sequence.
Remarks
The seedless Aggregate<TSource>(IEnumerable<TSource>, Func<TSource, TSource, TSource>) , which throws on an empty sequence because it has nothing to return. There is no such problem when the answer can say there was nothing to put together. Where a seed exists, Aggregate<TSource, TAccumulate>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>) is total and is the one to use.