Method ElementAtOrNone
- Namespace
- SodaFlow.Functional
- Assembly
- SodaFlow.Functional.dll
ElementAtOrNone<T>(IEnumerable<T>?, int)
Returns the element at a given position in a sequence, if there is one there.
[Pure]
public static Maybe<T> ElementAtOrNone<T>(this IEnumerable<T>? source, int index)
Parameters
sourceIEnumerable<T>The sequence to read. A null sequence counts as empty.
indexintThe zero-based position of the element to return.
Returns
- Maybe<T>
A Maybe<T> containing the element at
index, and one containing no value if the sequence is shorter than that orindexis negative.
Type Parameters
TThe type of the values in the sequence.
Remarks
A negative index gives no value rather than throwing, which is where this
differs from ElementAt<TSource>(IEnumerable<TSource>, int) and
agrees with
ElementAtOrDefault<TSource>(IEnumerable<TSource>, int).
This code indexes a sequence that permits an index. It enumerates each
other sequence to index and no more.