Skip to main content

Function: find()

Returns an iterable containing the first value of iterable for which fn returns a truthy value. Otherwise, returns an empty iterable.

Like Array.prototype.find, but for iterables.

Example

const iterable = [1, 2, `sloth`, 4, `other string`]

console.log(
pipe(
iterable,
find(value => typeof value === `string`),
or(() => `yawn!`),
)
)
//=> sloth

console.log(
pipe(
iterable,
find(value => Array.isArray(value)),
or(() => `yawn!`),
)
)
//=> yawn!

find(fn)

find<Value>(fn): (iterable) => Optional<Value>

Returns an iterable containing the first value of iterable for which fn returns a truthy value. Otherwise, returns an empty iterable.

Like Array.prototype.find, but for iterables.

Type Parameters

Value

Parameters

fn

Returns

Function

Parameters

iterable: Iterable<Value, any, any>

Returns

Optional<Value>

Example

const iterable = [1, 2, `sloth`, 4, `other string`]

console.log(
pipe(
iterable,
find(value => typeof value === `string`),
or(() => `yawn!`),
)
)
//=> sloth

console.log(
pipe(
iterable,
find(value => Array.isArray(value)),
or(() => `yawn!`),
)
)
//=> yawn!

Defined in

filters.d.ts:529

find(fn, iterable)

find<Value>(fn, iterable): Optional<Value>

Returns an iterable containing the first value of iterable for which fn returns a truthy value. Otherwise, returns an empty iterable.

Like Array.prototype.find, but for iterables.

Type Parameters

Value

Parameters

fn

iterable: Iterable<Value, any, any>

Returns

Optional<Value>

Example

const iterable = [1, 2, `sloth`, 4, `other string`]

console.log(
pipe(
iterable,
find(value => typeof value === `string`),
or(() => `yawn!`),
)
)
//=> sloth

console.log(
pipe(
iterable,
find(value => Array.isArray(value)),
or(() => `yawn!`),
)
)
//=> yawn!

Defined in

filters.d.ts:529