Skip to main content

Function: indexAsync()

indexAsync<Value>(asyncIterable): AsyncIterable<[number, Value], any, any>

Returns an async iterable equivalent to asyncIterable except each value of asyncIterable is placed in an entry containing the value's 0-based index in the iteration order followed by the value itself.

Type Parameters

Value

Parameters

asyncIterable: AsyncIterable<Value, any, any>

Returns

AsyncIterable<[number, Value], any, any>

Example

console.log(
await pipe(
asAsync([`sloth`, `more sloth`, `even more sloth`]),
indexAsync,
reduceAsync(toArray()),
),
)
//=> [ [ 0, 'sloth' ], [ 1, 'more sloth' ], [ 2, 'even more sloth' ] ]

Defined in

transforms.d.ts:310