Skip to content

Commit

Permalink
lodash: differenceBy/differenceWith update (#3707)
Browse files Browse the repository at this point in the history
* lodash: differenceBy/differenceWith update

* add tests, fix comparator

* Fix lodash tests

* Fix added test
  • Loading branch information
lukeapage authored and gantoine committed Jan 27, 2020
1 parent 9facc3c commit ae5262d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
12 changes: 6 additions & 6 deletions definitions/npm/lodash_v4.x.x/flow_v0.104.x-/lodash_v4.x.x.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,15 @@ declare module "lodash" {
array?: ?$ReadOnlyArray<T>,
...values: Array<?$ReadOnlyArray<T>>
): Array<T>;
differenceBy<T>(
differenceBy<T, U>(
array?: ?$ReadOnlyArray<T>,
values?: ?$ReadOnlyArray<T>,
iteratee?: ?ValueOnlyIteratee<T>
values?: ?$ReadOnlyArray<U>,
iteratee?: ?ValueOnlyIteratee<T | U>
): T[];
differenceWith<T>(
differenceWith<T, U>(
array?: ?$ReadOnlyArray<T>,
values?: ?$ReadOnlyArray<T>,
comparator?: ?Comparator<T>
values?: ?$ReadOnlyArray<U>,
comparator?: ?(item: T, item2: U) => boolean
): T[];
drop<T>(array?: ?Array<T>, n?: ?number): Array<T>;
dropRight<T>(array?: ?Array<T>, n?: ?number): Array<T>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import debounce from "lodash/debounce";
import defaultTo from "lodash/defaultTo";
import difference from "lodash/difference";
import differenceBy from "lodash/differenceBy";
import differenceWith from "lodash/differenceWith";
import each from "lodash/each";
import extend from "lodash/extend";
import find from "lodash/find";
Expand Down Expand Up @@ -86,6 +87,17 @@ difference(
differenceBy(([2.1, 1.2]: $ReadOnlyArray<*>), [2.3, 3.4], Math.floor);
differenceBy([{ x: 2 }, { x: 1 }], [{ x: 1 }], "x");

type A = {| a: 1 |};
type B = {| b: 1 |};
function diffTest(a: $ReadOnlyArray<A>, b: $ReadOnlyArray<B>) {
differenceBy(a, b, (x: A | B) => {
return x.a || x.b;
});
differenceWith(a, b, (x: A, y: B) => {
return x.a === y.b;
});
}

/**
* _.differenceBy
*/
Expand Down Expand Up @@ -355,7 +367,7 @@ zip([{ x: 1 }], [{ x: 2, y: 1 }])[0][2];
/**
* _.zipWith
*/
zipWith(["a", "b", "c"], [1, 2, 3], (str, num) => ({ [str]: num }));
zipWith(["a", "b", "c"], [1, 2, 3], (str, num) => ({ [string]: num }));
// $ExpectError `x` should be a `string`, `y` a `number`
zipWith(["a", "b", "c"], [1, 2, 3]).map(([x, y]) => x * y);

Expand Down

0 comments on commit ae5262d

Please sign in to comment.