[ramda] Add second type argument to eqBy to allow different codomain (#23926)

* Add second type argument to eqBy to allow different codomain

* Add test for new type argument

* Resolve unreachable function overload
This commit is contained in:
sgoll
2018-02-26 18:10:55 +01:00
committed by Andy
parent 9750d12776
commit f77d259e80
2 changed files with 11 additions and 4 deletions

View File

@@ -576,10 +576,9 @@ declare namespace R {
* Takes a function and two values in its domain and returns true if the values map to the same value in the
* codomain; false otherwise.
*/
eqBy<T>(fn: (a: T) => T, a: T, b: T): boolean;
eqBy<T>(fn: (a: T) => T, a: T): (b: T) => boolean;
eqBy<T>(fn: (a: T) => T): (a: T, b: T) => boolean;
eqBy<T>(fn: (a: T) => T): (a: T) => (b: T) => boolean;
eqBy<T, U = T>(fn: (a: T) => U, a: T, b: T): boolean;
eqBy<T, U = T>(fn: (a: T) => U, a: T): (b: T) => boolean;
eqBy<T, U = T>(fn: (a: T) => U): CurriedFunction2<T, T, boolean>;
/**
* Reports whether two functions have the same value for the specified property.

View File

@@ -2136,6 +2136,14 @@ class Rectangle {
const c: (a: any[]) => any[] = R.symmetricDifferenceWith(eqA)(l1); // => [{a: 1}, {a: 2}, {a: 5}, {a: 6}]
};
() => {
const eqL = R.eqBy<string, number>(s => s.length);
const l1 = ['bb', 'ccc', 'dddd'];
const l2 = ['aaa', 'bb', 'c'];
R.symmetricDifferenceWith(eqL, l1, l2); // => ['dddd', 'c']
R.symmetricDifferenceWith(eqL)(l1, l2); // => ['dddd', 'c']
};
/*****************************************************************
* String category
*/