Skip to main content

Function: or()

Returns the only value in iterable if it contains exactly one value. Otherwise, returns the result of invoking fn.

Example

console.log(pipe([`sloth`], or(() => `Never called`)))
//=> sloth

console.log(pipe([], or(() => `I get called!`)))
//=> I get called!

console.log(pipe([1, `sloth`, 3], or(() => `I also get called!`)))
//=> I also get called!

or(fn)

or<Value>(fn): (iterable) => Value

Returns the only value in iterable if it contains exactly one value. Otherwise, returns the result of invoking fn.

Type Parameters

Value

Parameters

fn

Returns

Function

Parameters

iterable: Iterable<Value, any, any>

Returns

Value

Example

console.log(pipe([`sloth`], or(() => `Never called`)))
//=> sloth

console.log(pipe([], or(() => `I get called!`)))
//=> I get called!

console.log(pipe([1, `sloth`, 3], or(() => `I also get called!`)))
//=> I also get called!

Defined in

optionals.d.ts:44

or(fn, iterable)

or<Value>(fn, iterable): Value

Returns the only value in iterable if it contains exactly one value. Otherwise, returns the result of invoking fn.

Type Parameters

Value

Parameters

fn

iterable: Iterable<Value, any, any>

Returns

Value

Example

console.log(pipe([`sloth`], or(() => `Never called`)))
//=> sloth

console.log(pipe([], or(() => `I get called!`)))
//=> I get called!

console.log(pipe([1, `sloth`, 3], or(() => `I also get called!`)))
//=> I also get called!

Defined in

optionals.d.ts:45