LinqExtensions.

SafeSingle<T>(IEnumerable<T>, Func<T, bool>) Method

Summary

provides a mechanism to use Single on a collection that returns a discriminated union instead of an exception.

Syntax

public static DiscriminatedUnion<T, MultipleResultsException, EmptySequenceException> SafeSingle<T>(this IEnumerable<T> sequence, Func<T, bool> predicate)

Type Parameters

Name Description
T

Parameters

Name Type Description
sequence IEnumerable<T>
predicate Func<T, bool>

Return Value

Type Description
DiscriminatedUnion<T, MultipleResultsException, EmptySequenceException>