Skip to content

,System.Func{--0,System.Boolean},--0)} ,System.Func{--0,System.Boolean},--0,System.Threading.CancellationToken)} )} ,System.Threading.CancellationToken)} ,--0)} ,--0,System.Threading.CancellationToken)}

ObservableAsync.FirstOrDefaultAsync(IObservableAsync, Func, T?) method

Defined in

Type: ObservableAsync Namespace: ReactiveUI.Extensions.Async Assembly: ReactiveUI.Extensions.dll

Applies to

net10.0, net10.0-browserwasm1.0, net10.0-desktop1.0, net9.0, net9.0-browserwasm1.0, net9.0-desktop1.0, net8.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.2, net8.0-macos14.5, net8.0-tvos17.2, netstandard2.1, net462, net481

Overloads

  • 1. public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this, Func<T, bool> predicate, T? defaultValue)
  • 2. public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this, Func<T, bool> predicate, T? defaultValue, CancellationToken cancellationToken)
  • 3. public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this)
  • 4. public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this, CancellationToken cancellationToken)
  • 5. public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this, T? defaultValue)
  • 6. public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this, T? defaultValue, CancellationToken cancellationToken)

1. Overload

public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this, Func<T, bool> predicate, T? defaultValue)

View source

Summary: Asynchronously returns the first element that matches the specified predicate, or a default value if no such element is found.

Type parameters

NameDescription
TThe type of elements in the source sequence.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.
predicateFuncA function to test each element for a condition. The method returns the first element for which this predicate returns true.
defaultValueT?The value to return if no element satisfies the predicate.

Returns: ValueTask -- A value task that represents the asynchronous operation. The result contains the first element that matches the predicate, or defaultValue if no such element is found.

2. Overload

public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this, Func<T, bool> predicate, T? defaultValue, CancellationToken cancellationToken)

Summary: Asynchronously returns the first element that matches the specified predicate, or a default value if no such element is found.

Type parameters

NameDescription
TThe type of elements in the source sequence.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.
predicateFuncA function to test each element for a condition. The method returns the first element for which this predicate returns true.
defaultValueT?The value to return if no element satisfies the predicate.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.

Returns: ValueTask -- A value task that represents the asynchronous operation. The result contains the first element that matches the predicate, or defaultValue if no such element is found.

3. Overload

public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this)

View source

Summary: Asynchronously returns the first element of the sequence, or a default value if the sequence contains no elements.

Type parameters

NameDescription
TThe type of elements in the source sequence.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.

Returns: ValueTask -- A value task that represents the asynchronous operation. The task result contains the first element of the sequence, or the default value for type T if the sequence is empty.

4. Overload

public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this, CancellationToken cancellationToken)

View source

Summary: Asynchronously returns the first element of the sequence, or a default value if the sequence contains no elements.

Type parameters

NameDescription
TThe type of elements in the source sequence.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.

Returns: ValueTask -- A value task that represents the asynchronous operation. The task result contains the first element of the sequence, or the default value for type T if the sequence is empty.

5. Overload

public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this, T? defaultValue)

View source

Summary: Asynchronously returns the first element of the sequence, or a specified default value if the sequence contains no elements.

Type parameters

NameDescription
TThe type of elements in the source sequence.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.
defaultValueT?The value to return if the sequence is empty.

Returns: ValueTask -- A task that represents the asynchronous operation. The task result contains the first element of the sequence, or defaultValue if the sequence is empty.

6. Overload

public static ValueTask<T?> FirstOrDefaultAsync<T>(this IObservableAsync<T> @this, T? defaultValue, CancellationToken cancellationToken)

Summary: Asynchronously returns the first element of the sequence, or a specified default value if the sequence contains no elements.

Type parameters

NameDescription
TThe type of elements in the source sequence.

Parameters

NameTypeDescription
this[IObservableAsync](#The source observable sequence.
defaultValueT?The value to return if the sequence is empty.
cancellationTokenCancellationTokenA cancellation token that can be used to cancel the asynchronous operation.

Returns: ValueTask -- A task that represents the asynchronous operation. The task result contains the first element of the sequence, or defaultValue if the sequence is empty.