deno.land / x / rambda@v9.1.1 / source / addIndex-spec.ts

addIndex-spec.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import {addIndex, map, pipe} from 'rambda'
describe('R.addIndex', () => { it('happy', () => { function mapFn<T>(fn: (x: T) => T, list: T[]) { const willReturn: T[] = [] list.forEach(item => { willReturn.push(fn(item)) })
return willReturn } const mapIndexed = addIndex(mapFn) const fn = (val: number, idx: number, list: number[]) => val + idx + 5 + list[0] const result = mapIndexed(fn)([1, 2, 3]) result // $ExpectType any[] }) it('with pipe', () => { const result = pipe( addIndex(map)((x: number, i: number) => { return x + i }) )([1, 2, 3]) result // $ExpectType any[] })})
rambda

Version Info

Tagged at
2 months ago