Table of Contents

Method FirstOrNone

Namespace
SodaFlow.Functional
Assembly
SodaFlow.Functional.dll

FirstOrNone<T>(IEnumerable<T>?)

Returns the first element of a sequence, if it has one.

[Pure]
public static Maybe<T> FirstOrNone<T>(this IEnumerable<T>? source)

Parameters

source IEnumerable<T>

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

Returns

Maybe<T>

A Maybe<T> containing the first element, and one containing no value if the sequence is empty.

Type Parameters

T

The type of the values in the sequence.

Remarks

Reads at most one element of the source.

FirstOrNone<T>(IEnumerable<T>?, Func<T, bool>)

Returns the first element of a sequence which satisfies a predicate, if there is one.

[Pure]
public static Maybe<T> FirstOrNone<T>(this IEnumerable<T>? source, Func<T, bool> predicate)

Parameters

source IEnumerable<T>

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

predicate Func<T, bool>

The condition the element must satisfy.

Returns

Maybe<T>

A Maybe<T> containing the first matching element, and one containing no value if there is none.

Type Parameters

T

The type of the values in the sequence.

Remarks

Stops at the first element that satisfies it.