Method AllSomeOrNone
- Namespace
- SodaFlow.Functional
- Assembly
- SodaFlow.Functional.dll
AllSomeOrNone<T>(IEnumerable<Maybe<T>>?)
Turns a sequence of values that can be missing into a sequence that can be missing, which has a value only when each entry was.
[Pure]
public static Maybe<IEnumerable<T>> AllSomeOrNone<T>(this IEnumerable<Maybe<T>>? o)
Parameters
oIEnumerable<Maybe<T>>The sequence to collect. A null sequence counts as empty.
Returns
- Maybe<IEnumerable<T>>
All the values if each entry had one, and no value if any entry did not. An empty sequence gives an empty sequence rather than no value.
Type Parameters
TThe type of the values in the sequence.
Remarks
Unlike WhereSome<T>(IEnumerable<Maybe<T>>?), this enumerates the source immediately. No code can know if the result has a value without a read to the end of it.
AllSomeOrNone<T, TResult>(IEnumerable<T>?, Func<T, Maybe<TResult>>)
Applies a function which can give no value to each element of a sequence, and collects the results only when each one has a value.
[Pure]
public static Maybe<IEnumerable<TResult>> AllSomeOrNone<T, TResult>(this IEnumerable<T>? o, Func<T, Maybe<TResult>> f)
Parameters
oIEnumerable<T>The sequence to map. A null sequence counts as empty.
fFunc<T, Maybe<TResult>>Applied to each element in turn.
Returns
- Maybe<IEnumerable<TResult>>
All the results if
fproduced a value for each element, and no value if it did not give one for any. An empty sequence gives an empty sequence rather than no value.
Type Parameters
TThe type of the values in the sequence.
TResultThe type of the values the function produces.
Remarks
This is the all-or-nothing counterpart to
Choose<T, TResult>(IEnumerable<T>?, Func<T, Maybe<TResult>>)
, which keeps whatever it can get and discards the others. Use this one
where one element that fails makes the full result meaningless. An example
is a parse of a file of numbers, and not a selection of the numbers in a
file of mixed lines.
Like the other overload this enumerates the source immediately.
f runs on each element, and a value of none from one
element does not stop it. Thus, it must not be dependent on a stop before
the end.