Skip to content

Documentation / @eventkit/base / first

Function: first() ​

Call Signature ​

ts
function first<T, D>(predicate?, defaultValue?): SingletonOperatorFunction<T, T | D>

Emits the first value emitted by the source observable that satisfies a specified condition. If no such value is found when the source observable completes, the defaultValue is emitted if it's provided. If it isn't, a NoValuesError is thrown.

Type Parameters ​

Type ParameterDefault type
T-
DT

Parameters ​

ParameterTypeDescription
predicate?nullA function that evaluates each value emitted by the source observable. Returns true if the value satisfies the condition, false otherwise.
defaultValue?DThe default value returned when no value matches the predicate.

Returns ​

SingletonOperatorFunction<T, T | D>

Throws ​

Will throw a NoValuesError if no value is found and no default value is provided.

Call Signature ​

ts
function first<T>(predicate): SingletonOperatorFunction<T, TruthyTypesOf<T>>

Emits the first value emitted by the source observable that satisfies a specified condition. If no such value is found when the source observable completes, the defaultValue is emitted if it's provided. If it isn't, a NoValuesError is thrown.

Type Parameters ​

Type Parameter
T

Parameters ​

ParameterTypeDescription
predicateBooleanConstructorA function that evaluates each value emitted by the source observable. Returns true if the value satisfies the condition, false otherwise.

Returns ​

SingletonOperatorFunction<T, TruthyTypesOf<T>>

Throws ​

Will throw a NoValuesError if no value is found and no default value is provided.

Call Signature ​

ts
function first<T, D>(predicate, defaultValue): SingletonOperatorFunction<T, D | TruthyTypesOf<T>>

Emits the first value emitted by the source observable that satisfies a specified condition. If no such value is found when the source observable completes, the defaultValue is emitted if it's provided. If it isn't, a NoValuesError is thrown.

Type Parameters ​

Type Parameter
T
D

Parameters ​

ParameterTypeDescription
predicateBooleanConstructorA function that evaluates each value emitted by the source observable. Returns true if the value satisfies the condition, false otherwise.
defaultValueDThe default value returned when no value matches the predicate.

Returns ​

SingletonOperatorFunction<T, D | TruthyTypesOf<T>>

Throws ​

Will throw a NoValuesError if no value is found and no default value is provided.

Call Signature ​

ts
function first<T, S>(predicate, defaultValue?): SingletonOperatorFunction<T, S>

Emits the first value emitted by the source observable that satisfies a specified condition. If no such value is found when the source observable completes, the defaultValue is emitted if it's provided. If it isn't, a NoValuesError is thrown.

Type Parameters ​

Type Parameter
T
S

Parameters ​

ParameterTypeDescription
predicate(value, index) => value is SA function that evaluates each value emitted by the source observable. Returns true if the value satisfies the condition, false otherwise.
defaultValue?SThe default value returned when no value matches the predicate.

Returns ​

SingletonOperatorFunction<T, S>

Throws ​

Will throw a NoValuesError if no value is found and no default value is provided.

Call Signature ​

ts
function first<T, S, D>(predicate, defaultValue): SingletonOperatorFunction<T, S | D>

Emits the first value emitted by the source observable that satisfies a specified condition. If no such value is found when the source observable completes, the defaultValue is emitted if it's provided. If it isn't, a NoValuesError is thrown.

Type Parameters ​

Type Parameter
T
S
D

Parameters ​

ParameterTypeDescription
predicate(value, index) => value is SA function that evaluates each value emitted by the source observable. Returns true if the value satisfies the condition, false otherwise.
defaultValueDThe default value returned when no value matches the predicate.

Returns ​

SingletonOperatorFunction<T, S | D>

Throws ​

Will throw a NoValuesError if no value is found and no default value is provided.

Call Signature ​

ts
function first<T, D>(predicate, defaultValue?): SingletonOperatorFunction<T, T | D>

Emits the first value emitted by the source observable that satisfies a specified condition. If no such value is found when the source observable completes, the defaultValue is emitted if it's provided. If it isn't, a NoValuesError is thrown.

Type Parameters ​

Type ParameterDefault type
T-
DT

Parameters ​

ParameterTypeDescription
predicate(value, index) => booleanA function that evaluates each value emitted by the source observable. Returns true if the value satisfies the condition, false otherwise.
defaultValue?DThe default value returned when no value matches the predicate.

Returns ​

SingletonOperatorFunction<T, T | D>

Throws ​

Will throw a NoValuesError if no value is found and no default value is provided.

Released under the MIT License.