Skip to main content

Function: atAsync()

Returns an async iterable containing the value at the given index of asyncIterable or an empty async iterable if index is out of bounds.

WARNING: This function linearly iterates up to index because async iterables do not support random access.

Throws

if index is not a non-negative integer.

Example

const asyncIterable = asAsync([`sloth`, `more sloth`, `even more sloth`])

console.log(
await pipe(
asyncIterable,
atAsync(1),
getAsync,
),
)
//=> 'more sloth'

Since

v3.5.0

Call Signature

atAsync<Index>(index): <Value>(asyncIterable) => AsyncOptional<Value>

Type Parameters

Index extends number

Parameters

index

NonNegativeInteger<Index>

Returns

Function

Type Parameters

Value

Parameters

asyncIterable

AsyncIterable<Value, any, any>

Returns

AsyncOptional<Value>

Defined in

splices.d.ts:808

Call Signature

atAsync<Index, Value>(index, asyncIterable): AsyncOptional<Value>

Type Parameters

Index extends number

Value

Parameters

index

NonNegativeInteger<Index>

asyncIterable

AsyncIterable<Value, any, any>

Returns

AsyncOptional<Value>

Defined in

splices.d.ts:811