Skip to main content
Module

x/ramda/innerJoin.js

:ram: Practical functional Javascript
Very Popular
Go to Latest
File
import _includesWith from './internal/_includesWith';import _curry3 from './internal/_curry3';import _filter from './internal/_filter';

/** * Takes a predicate `pred`, a list `xs`, and a list `ys`, and returns a list * `xs'` comprising each of the elements of `xs` which is equal to one or more * elements of `ys` according to `pred`. * * `pred` must be a binary function expecting an element from each list. * * `xs`, `ys`, and `xs'` are treated as sets, semantically, so ordering should * not be significant, but since `xs'` is ordered the implementation guarantees * that its values are in the same order as they appear in `xs`. Duplicates are * not removed, so `xs'` may contain duplicates if `xs` contains duplicates. * * @func * @memberOf R * @since v0.24.0 * @category Relation * @sig ((a, b) -> Boolean) -> [a] -> [b] -> [a] * @param {Function} pred * @param {Array} xs * @param {Array} ys * @return {Array} * @see R.intersection * @example * * R.innerJoin( * (record, id) => record.id === id, * [{id: 824, name: 'Richie Furay'}, * {id: 956, name: 'Dewey Martin'}, * {id: 313, name: 'Bruce Palmer'}, * {id: 456, name: 'Stephen Stills'}, * {id: 177, name: 'Neil Young'}], * [177, 456, 999] * ); * //=> [{id: 456, name: 'Stephen Stills'}, {id: 177, name: 'Neil Young'}] */var innerJoin = _curry3(function innerJoin(pred, xs, ys) { return _filter(function(x) { return _includesWith(pred, x, ys); }, xs);});export default innerJoin;