UNPKG

1.62 kBJavaScriptView Raw
1var _includesWith =
2/*#__PURE__*/
3require("./internal/_includesWith");
4
5var _curry3 =
6/*#__PURE__*/
7require("./internal/_curry3");
8
9var _filter =
10/*#__PURE__*/
11require("./internal/_filter");
12/**
13 * Takes a predicate `pred`, a list `xs`, and a list `ys`, and returns a list
14 * `xs'` comprising each of the elements of `xs` which is equal to one or more
15 * elements of `ys` according to `pred`.
16 *
17 * `pred` must be a binary function expecting an element from each list.
18 *
19 * `xs`, `ys`, and `xs'` are treated as sets, semantically, so ordering should
20 * not be significant, but since `xs'` is ordered the implementation guarantees
21 * that its values are in the same order as they appear in `xs`. Duplicates are
22 * not removed, so `xs'` may contain duplicates if `xs` contains duplicates.
23 *
24 * @func
25 * @memberOf R
26 * @since v0.24.0
27 * @category Relation
28 * @sig ((a, b) -> Boolean) -> [a] -> [b] -> [a]
29 * @param {Function} pred
30 * @param {Array} xs
31 * @param {Array} ys
32 * @return {Array}
33 * @see R.intersection
34 * @example
35 *
36 * R.innerJoin(
37 * (record, id) => record.id === id,
38 * [{id: 824, name: 'Richie Furay'},
39 * {id: 956, name: 'Dewey Martin'},
40 * {id: 313, name: 'Bruce Palmer'},
41 * {id: 456, name: 'Stephen Stills'},
42 * {id: 177, name: 'Neil Young'}],
43 * [177, 456, 999]
44 * );
45 * //=> [{id: 456, name: 'Stephen Stills'}, {id: 177, name: 'Neil Young'}]
46 */
47
48
49var innerJoin =
50/*#__PURE__*/
51_curry3(function innerJoin(pred, xs, ys) {
52 return _filter(function (x) {
53 return _includesWith(pred, x, ys);
54 }, xs);
55});
56
57module.exports = innerJoin;
\No newline at end of file