Skip to content

Commit

Permalink
complete ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Deyan Totev committed Jul 17, 2023
1 parent fb664da commit dba8ffc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
12 changes: 3 additions & 9 deletions files/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5327,8 +5327,6 @@ Explanation:
Example:
```
const result = R.addIndex()
// =>
```
Categories:
Expand All @@ -5337,8 +5335,7 @@ Notes:
*/
// @SINGLE_MARKER
export function addIndex<T, U>(f: any): (fn: Iterator<T, U>, list: T[]) => U[];
export function addIndex<T, U>(f: any, fn: Iterator<T, U>): (fn: Iterator<T, U>, list: T[]) => U[];
export function addIndex(originalFn: any): (fn: any) => (list: any[]) => any[];

/*
Method: ap
Expand All @@ -5348,8 +5345,6 @@ Explanation:
Example:
```
const result = R.ap()
// =>
```
Categories:
Expand All @@ -5361,6 +5356,7 @@ Notes:
export function ap<T, U>(fns: Array<(a: T) => U>[], vs: T[]): U[];
export function ap<T, U>(fns: Array<(a: T) => U>): (vs: T[]) => U[];
export function ap<R, A, B>(fn: (r: R, a: A) => B, fn1: (r: R) => A): (r: R) => B;

/*
Method: addIndexRight
Expand All @@ -5369,8 +5365,6 @@ Explanation:
Example:
```
const result = R.addIndexRight()
// =>
```
Categories:
Expand All @@ -5379,7 +5373,7 @@ Notes:
*/
// @SINGLE_MARKER
export function addIndexRight<T>(x: T): T;
export function addIndexRight(originalFn: any): (fn: any) => (list: any[]) => any[];

// RAMBDAX_MARKER_START

Expand Down
36 changes: 29 additions & 7 deletions source/addIndex-spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
import {addIndex} from 'ramda'
import * as R from 'rambda'
import * as Ramda from 'ramda'

describe('R.addIndex', () => {
it('happy', () => {
const withIndex = addIndex()
function mapFn<T>(fn: (x: T) => T, list: T[]) {
const willReturn: T[] = []
list.forEach(item => {
willReturn.push(fn(item))
})

result // $ExpectType number
return willReturn
}
const mapIndexed = R.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('curried', () => {
const result = addIndex()

result // $ExpectType number
it('with Ramda.pipe', () => {
const result = Ramda.pipe(
Ramda.addIndex(R.map)((x: number, i: number) => {
return x + i
})
)([1, 2, 3])
result // $ExpectType unknown
})
it('with Rambda.pipe', () => {
const result = R.pipe(
R.addIndex(Ramda.map)((x: number, i: number) => {
return x + i
})
)([1, 2, 3])
result // $ExpectType any[]
})
})
7 changes: 7 additions & 0 deletions source/addIndex.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import * as R from 'ramda'

import { addIndex } from './addIndex.js'
import { map } from './map.js'

test('with R.pipe', () => {
const result = R.pipe(R.addIndex(R.map)((x, i) => x + i))([ 1, 2, 3 ])
expect(result).toEqual([ 1, 3, 5 ])
})

test('happy', () => {
function mapFn(fn, list){
const willReturn = []
Expand Down

0 comments on commit dba8ffc

Please sign in to comment.