Skip to main content

Variable: index()

const index: <Value>(iterable) => Iterable<[number, Value]>

Defined in: transforms.d.ts:456

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

Type Parameters

Value

Value

Parameters

iterable

Iterable<Value>

Returns

Iterable<[number, Value]>

Example

import { index, join, map, pipe, reduce } from 'lfi'

console.log(
pipe(
[`sloth`, `lazy`, `sleep`],
index,
map(([index, word]) => `${index + 1}. ${word}`),
join(`\n`),
),
)
//=> 1. sloth
//=> 2. lazy
//=> 3. sleep
Playground

Since

v2.0.0