/// <summary> /// Returns the first element in a sequence that satisfies a specified condition. /// </summary> /// <typeparam name="T">The type of the elements of source.</typeparam> /// <param name="seq">A collection to return an element from.</param> /// <param name="filter">A function to test each element for a condition.</param> /// <param name="token">The token that can be used to cancel enumeration.</param> /// <returns>The first element in the sequence that matches to the specified filter; or empty value.</returns> /// <exception cref="OperationCanceledException">The operation has been canceled.</exception> public static ValueTask <Optional <T> > FirstOrEmptyAsync <T>(IAsyncEnumerable <T> seq, ValueFunc <T, bool> filter, CancellationToken token = default) where T : notnull => NewSequence.FirstOrEmptyAsync(seq, filter, token);
/// <summary> /// Obtains first value in the sequence; or <see cref="Optional{T}.None"/> /// if sequence is empty. /// </summary> /// <typeparam name="T">Type of elements in the sequence.</typeparam> /// <param name="seq">A sequence to check. Cannot be <see langword="null"/>.</param> /// <param name="token">The token that can be used to cancel enumeration.</param> /// <returns>The first element in the sequence; or <see cref="Optional{T}.None"/> if sequence is empty. </returns> /// <exception cref="OperationCanceledException">The operation has been canceled.</exception> public static ValueTask <Optional <T> > FirstOrEmptyAsync <T>(IAsyncEnumerable <T> seq, CancellationToken token = default) => NewSequence.FirstOrEmptyAsync(seq, token);