import { pipe, intersection, isEmpty, curryN } from 'ramda';
import isNotEmpty from './isNotEmpty';
/**
* Returns true if two lists have at least one element common to both lists.
*
* @func overlaps
* @memberOf RA
* @category Relation
* @since {@link https://char0n.github.io/ramda-adjunct/2.30.0|v2.30.0}
* @sig [a] -> [a] -> Boolean
* @param {Array} list1 The first list
* @param {Array} list2 The second list
* @return {boolean} True if two lists have at least one element common to both lists
* @example
*
* RA.overlaps(['-v', '--verbose'], ['node', 'script.js', '-v']); //=> true
* RA.overlaps(['-v', '--verbose'], []); //=> false
* RA.overlaps([1, 2, 3], [3, 4, 5]); //=> true
* RA.overlaps([1, 2, 3], [4, 5]); //=> false
*/
const overlaps = curryN(2, (list1, list2) => {
if (isEmpty(list1)) {
return true;
}
return pipe(intersection, isNotEmpty)(list1, list2);
});
export default overlaps;