call.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import _curry1 from "./internal/_curry1.js";
  2. /**
  3. * Returns the result of calling its first argument with the remaining
  4. * arguments. This is occasionally useful as a converging function for
  5. * [`R.converge`](#converge): the first branch can produce a function while the
  6. * remaining branches produce values to be passed to that function as its
  7. * arguments.
  8. *
  9. * @func
  10. * @memberOf R
  11. * @since v0.9.0
  12. * @category Function
  13. * @sig ((*... -> a), *...) -> a
  14. * @param {Function} fn The function to apply to the remaining arguments.
  15. * @param {...*} args Any number of positional arguments.
  16. * @return {*}
  17. * @see R.apply
  18. * @example
  19. *
  20. * R.call(R.add, 1, 2); //=> 3
  21. *
  22. * const indentN = R.pipe(
  23. * R.repeat(' '),
  24. * R.join(''),
  25. * R.replace(/^(?!$)/gm)
  26. * );
  27. *
  28. * const format = R.converge(
  29. * R.call,
  30. * [
  31. * R.pipe(R.prop('indent'), indentN),
  32. * R.prop('value')
  33. * ]
  34. * );
  35. *
  36. * format({indent: 2, value: 'foo\nbar\nbaz\n'}); //=> ' foo\n bar\n baz\n'
  37. * @symb R.call(f, a, b) = f(a, b)
  38. */
  39. var call =
  40. /*#__PURE__*/
  41. _curry1(function call(fn) {
  42. return fn.apply(this, Array.prototype.slice.call(arguments, 1));
  43. });
  44. export default call;