@types/ramda Update chain to support functions returning readonly arrays and tuples (#41163)

This commit is contained in:
Tom Widmer
2019-12-26 11:21:38 -06:00
committed by Andrew Branch
parent 93ec437a0d
commit c702e1cd8a
2 changed files with 16 additions and 2 deletions
+2 -2
View File
@@ -242,8 +242,8 @@ export function call(fn: (...args: readonly any[]) => (...args: readonly any[])
* `chain` maps a function over a list and concatenates the results.
* This implementation is compatible with the Fantasy-land Chain spec
*/
export function chain<T, U>(fn: (n: T) => U[], list: readonly T[]): U[];
export function chain<T, U>(fn: (n: T) => U[]): (list: readonly T[]) => U[];
export function chain<T, U>(fn: (n: T) => readonly U[], list: readonly T[]): U[];
export function chain<T, U>(fn: (n: T) => readonly U[]): (list: readonly T[]) => U[];
export function chain<X0, X1, R>(fn: (x0: X0, x1: X1) => R, fn1: (x1: X1) => X0): (x1: X1) => R;
/**
+14
View File
@@ -5,10 +5,24 @@ import * as R from 'ramda';
return [n, n];
}
function duplicateConst(n: number) {
return [n, n] as const;
}
function duplicateReadonly(n: number): ReadonlyArray<number> {
return [n, n];
}
R.chain(duplicate, [1, 2, 3]); // => [1, 1, 2, 2, 3, 3]
R.chain(duplicate)([1, 2, 3]); // => [1, 1, 2, 2, 3, 3]
const result1: number[] = R.chain<number, number[], number[]>(
R.append,
R.head,
)([1, 2, 3]); // => [1, 2, 3, 1]
R.chain(duplicateConst, [1, 2, 3] as const); // => [1, 1, 2, 2, 3, 3]
R.chain(duplicateConst)([1, 2, 3] as const); // => [1, 1, 2, 2, 3, 3]
R.chain(duplicateReadonly, [1, 2, 3]); // => [1, 1, 2, 2, 3, 3]
R.chain(duplicateReadonly)([1, 2, 3]); // => [1, 1, 2, 2, 3, 3]
};