tap.js 836 B

12345678910111213141516171819202122232425262728293031323334
  1. import _curry2 from "./internal/_curry2.js";
  2. import _dispatchable from "./internal/_dispatchable.js";
  3. import _xtap from "./internal/_xtap.js";
  4. /**
  5. * Runs the given function with the supplied object, then returns the object.
  6. *
  7. * Acts as a transducer if a transformer is given as second parameter.
  8. *
  9. * @func
  10. * @memberOf R
  11. * @since v0.1.0
  12. * @category Function
  13. * @sig (a -> *) -> a -> a
  14. * @param {Function} fn The function to call with `x`. The return value of `fn` will be thrown away.
  15. * @param {*} x
  16. * @return {*} `x`.
  17. * @example
  18. *
  19. * const sayX = x => console.log('x is ' + x);
  20. * R.tap(sayX, 100); //=> 100
  21. * // logs 'x is 100'
  22. * @symb R.tap(f, a) = (f(a), a)
  23. */
  24. var tap =
  25. /*#__PURE__*/
  26. _curry2(
  27. /*#__PURE__*/
  28. _dispatchable([], _xtap, function tap(fn, x) {
  29. fn(x);
  30. return x;
  31. }));
  32. export default tap;