Table of Contents

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

source IEnumerable<T>

The sequence to read. A null sequence counts as empty.

index int

The 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 or index is negative.

Type Parameters

T

The 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.