BACK
Referencesingle
Reference · 99

single

Expects exactly one matching value.

Signature

single(predicate?: (value: T, index: number) => boolean): OperatorFunction

What it does

Emits a value only if source contains exactly one matching element. If there are zero or more than one, it fails with an error.

When to use

Invariants: there must be exactly one selected user, exactly one primary item, exactly one result.

Gotcha

For "the first match", use first/find. single checks uniqueness and can throw an error.

See also

first, find

script.ts // TypeScript
CONSOLE · Console output
Hit Run to see the result...