Merge pull request #26180 from rayhaneh/Ramda-differenceWith-Typing-Different-Lists

[ramda] Modified differenceWith typing to accept lists of different types
This commit is contained in:
Benjamin Lichtman
2018-05-31 15:22:23 -07:00
committed by GitHub
2 changed files with 12 additions and 8 deletions

View File

@@ -523,9 +523,9 @@ declare namespace R {
* Duplication is determined according to the value returned by applying the supplied predicate to two list
* elements.
*/
differenceWith<T>(pred: (a: T, b: T) => boolean, list1: ReadonlyArray<T>, list2: ReadonlyArray<T>): T[];
differenceWith<T>(pred: (a: T, b: T) => boolean): (list1: ReadonlyArray<T>, list2: ReadonlyArray<T>) => T[];
differenceWith<T>(pred: (a: T, b: T) => boolean, list1: ReadonlyArray<T>): (list2: ReadonlyArray<T>) => T[];
differenceWith<T1, T2>(pred: (a: T1, b: T2) => boolean, list1: ReadonlyArray<T1>, list2: ReadonlyArray<T2>): T1[];
differenceWith<T1, T2>(pred: (a: T1, b: T2) => boolean): (list1: ReadonlyArray<T1>, list2: ReadonlyArray<T2>) => T1[];
differenceWith<T1, T2>(pred: (a: T1, b: T2) => boolean, list1: ReadonlyArray<T1>): (list2: ReadonlyArray<T2>) => T1[];
/*
* Returns a new object that does not contain a prop property.

View File

@@ -1950,19 +1950,23 @@ class Rectangle {
};
() => {
function cmp(x: any, y: any) {
function cmp1(x: any, y: any) {
return x.a === y.a;
}
function cmp2(x: any, y: any) {
return x.a === y.b;
}
const l1 = [{a: 1}, {a: 2}, {a: 3}];
const l2 = [{a: 3}, {a: 4}];
R.differenceWith(cmp, l1, l2); // => [{a: 1}, {a: 2}]
const l3 = [{b: 3}, {b: 4}];
R.differenceWith(cmp1, l1, l2); // => [{a: 1}, {a: 2}]
const differenceWithCurried1 = R.differenceWith(cmp);
const differenceWithCurried1 = R.differenceWith(cmp1);
differenceWithCurried1(l1, l2); // =>[{a: 1}, {a: 2}]
const differenceWithCurried2 = R.differenceWith(cmp, l1);
differenceWithCurried2(l2); // =>[{a: 1}, {a: 2}]
R.differenceWith(cmp2, l1, l3); // => [{a: 1}, {a: 2}]
};
() => {