Skip to main content

Function: findLastAsync()

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

Example

const asyncIterable = asAsync([1, 2, `sloth`, 4, `other string`])

console.log(
await pipe(
asyncIterable,
findLastAsync(value => typeof value === `string`),
orAsync(() => `yawn!`),
),
)
//=> other string

console.log(
await pipe(
asyncIterable,
findLastAsync(value => Array.isArray(value)),
orAsync(() => `yawn!`),
),
)
//=> yawn!

findLastAsync(fn)

findLastAsync<Value>(fn): (asyncIterable) => AsyncOptional<Value>

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

Type Parameters

Value

Parameters

fn

Returns

Function

Parameters

asyncIterable: AsyncIterable<Value, any, any>

Returns

AsyncOptional<Value>

Example

const asyncIterable = asAsync([1, 2, `sloth`, 4, `other string`])

console.log(
await pipe(
asyncIterable,
findLastAsync(value => typeof value === `string`),
orAsync(() => `yawn!`),
),
)
//=> other string

console.log(
await pipe(
asyncIterable,
findLastAsync(value => Array.isArray(value)),
orAsync(() => `yawn!`),
),
)
//=> yawn!

Defined in

filters.d.ts:660

findLastAsync(fn, asyncIterable)

findLastAsync<Value>(fn, asyncIterable): AsyncOptional<Value>

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

Type Parameters

Value

Parameters

fn

asyncIterable: AsyncIterable<Value, any, any>

Returns

AsyncOptional<Value>

Example

const asyncIterable = asAsync([1, 2, `sloth`, 4, `other string`])

console.log(
await pipe(
asyncIterable,
findLastAsync(value => typeof value === `string`),
orAsync(() => `yawn!`),
),
)
//=> other string

console.log(
await pipe(
asyncIterable,
findLastAsync(value => Array.isArray(value)),
orAsync(() => `yawn!`),
),
)
//=> yawn!

Defined in

filters.d.ts:660