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