on.js 906 B

123456789101112131415161718192021222324252627282930313233
  1. import curryN from "./internal/_curryN.js";
  2. /**
  3. * Takes a binary function `f`, a unary function `g`, and two values.
  4. * Applies `g` to each value, then applies the result of each to `f`.
  5. *
  6. * Also known as the P combinator.
  7. *
  8. * @func
  9. * @memberOf R
  10. * @since v0.28.0
  11. * @category Function
  12. * @sig ((a, a) -> b) -> (c -> a) -> c -> c -> b
  13. * @param {Function} f a binary function
  14. * @param {Function} g a unary function
  15. * @param {any} a any value
  16. * @param {any} b any value
  17. * @return {any} The result of `f`
  18. * @example
  19. *
  20. * const eqBy = R.on((a, b) => a === b);
  21. * eqBy(R.prop('a'), {b:0, a:1}, {a:1}) //=> true;
  22. *
  23. * const containsInsensitive = R.on(R.includes, R.toLower);
  24. * containsInsensitive('o', 'FOO'); //=> true
  25. * @symb R.on(f, g, a, b) = f(g(a), g(b))
  26. */
  27. var on =
  28. /*#__PURE__*/
  29. curryN(4, [], function on(f, g, a, b) {
  30. return f(g(a), g(b));
  31. });
  32. export default on;