Skip to main content

Function: findLast()

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

Example

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

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

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

findLast(fn)

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

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

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,
findLast(value => typeof value === `string`),
or(() => `yawn!`),
),
)
//=> other string

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

Defined in

filters.d.ts:628

findLast(fn, iterable)

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

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

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,
findLast(value => typeof value === `string`),
or(() => `yawn!`),
),
)
//=> other string

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

Defined in

filters.d.ts:628