Class MaybeCollectionExtensions
- Namespace
- Trellis
- Assembly
- Trellis.Results.dll
Extension methods for safely querying collections, returning Maybe<T> instead of throwing.
public static class MaybeCollectionExtensions
- Inheritance
-
MaybeCollectionExtensions
- Inherited Members
Methods
TryFirst<T>(IEnumerable<T>)
Returns the first element of a sequence wrapped in a Maybe<T>, or None if the sequence contains no elements.
public static Maybe<T> TryFirst<T>(this IEnumerable<T> source) where T : notnull
Parameters
sourceIEnumerable<T>The sequence to return the first element of.
Returns
Type Parameters
TThe type of the elements of
source.
Exceptions
- ArgumentNullException
Thrown when
sourceis null.
TryFirst<T>(IEnumerable<T>, Func<T, bool>)
Returns the first element of a sequence that satisfies a condition wrapped in a Maybe<T>, or None if no such element is found.
public static Maybe<T> TryFirst<T>(this IEnumerable<T> source, Func<T, bool> predicate) where T : notnull
Parameters
sourceIEnumerable<T>The sequence to search.
predicateFunc<T, bool>A function to test each element for a condition.
Returns
Type Parameters
TThe type of the elements of
source.
Exceptions
- ArgumentNullException
Thrown when
sourceorpredicateis null.
TryLast<T>(IEnumerable<T>)
Returns the last element of a sequence wrapped in a Maybe<T>, or None if the sequence contains no elements.
public static Maybe<T> TryLast<T>(this IEnumerable<T> source) where T : notnull
Parameters
sourceIEnumerable<T>The sequence to return the last element of.
Returns
Type Parameters
TThe type of the elements of
source.
Exceptions
- ArgumentNullException
Thrown when
sourceis null.
TryLast<T>(IEnumerable<T>, Func<T, bool>)
Returns the last element of a sequence that satisfies a condition wrapped in a Maybe<T>, or None if no such element is found.
public static Maybe<T> TryLast<T>(this IEnumerable<T> source, Func<T, bool> predicate) where T : notnull
Parameters
sourceIEnumerable<T>The sequence to search.
predicateFunc<T, bool>A function to test each element for a condition.
Returns
Type Parameters
TThe type of the elements of
source.
Exceptions
- ArgumentNullException
Thrown when
sourceorpredicateis null.