,System.Boolean,-0,System.Threading.CancellationToken)}
SingleElementWitness(Func?, bool, T?, CancellationToken) constructor¶
Defined in
Type: SingleElementWitnessReactiveUI.Primitives.Async.Advanced
Assembly: ReactiveUI.Primitives.Async.Core.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
public SingleElementWitness(Func<T, bool>? predicate, bool requireExactlyOne, T? defaultValue, CancellationToken cancellationToken)
Summary:
Shared observer used by both SingleAsync and SingleOrDefaultAsync. The two operator
surfaces previously held near-identical observer classes; the only behavioural difference is
whether an empty sequence throws or returns a caller-supplied default. That difference is now a
single flag on this type, so the OnNext / OnErrorResume / OnCompleted bodies live in one place.
Parameters
| Name | Type | Description |
|---|---|---|
predicate | Func | An optional predicate to filter elements; null matches all elements. |
requireExactlyOne | bool | When true (the SingleAsync shape), an empty sequence completes the result task with an InvalidOperationException. When false (the SingleOrDefaultAsync shape), an empty sequence resolves the result task with defaultValue. |
defaultValue | T? | The value to return on empty when requireExactlyOne is false. |
cancellationToken | CancellationToken | A cancellation token for the operation. |