Ramda Adjunct 4.0.0

isPair.js

  1. import { both, equals, length, pipe, curryN } from 'ramda';
  2. import isArray from './isArray';
  3. /**
  4. * Checks if input value is a pair.
  5. *
  6. * @func isPair
  7. * @memberOf RA
  8. * @since {@link https://char0n.github.io/ramda-adjunct/1.19.0|v1.19.0}
  9. * @category Type
  10. * @sig * -> Boolean
  11. * @param {*} val The value to test
  12. * @return {boolean}
  13. * @see {@link http://ramdajs.com/docs/#pair|R.pair}, {@link RA.isNotPair|isNotPair}
  14. * @example
  15. *
  16. * RA.isPair([]); // => false
  17. * RA.isPair([0]); // => false
  18. * RA.isPair([0, 1]); // => true
  19. * RA.isPair([0, 1, 2]); // => false
  20. * RA.isPair({ 0: 0, 1: 1 }); // => false
  21. * RA.isPair({ foo: 0, bar: 0 }); // => false
  22. */
  23. const isPair = curryN(1, both(isArray, pipe(length, equals(2))));
  24. export default isPair;