omnibelt/tap.js

  1. const curry = require('ramda/src/curry');
  2. /**
  3. * Runs the given function with the supplied object, then returns the object.
  4. *
  5. * @signature (a -> *) -> a -> a
  6. *
  7. * @example
  8. * tap((x) => return 'bar')('foo'); // 'foo'
  9. * tap(console.log)('foo'); // 'foo' (and it will have been logged)
  10. * compose(
  11. * split,
  12. * tap((x) => dbRemoveUserByName(x)), // unrelated, but you won't have a handle on this promise
  13. * toLower,
  14. * )('USER NAME');
  15. * // ['u', 's', 'e', 'r', 'n', 'a', 'm', 'e']
  16. * // And the promise will have been kicked off to remove that user by name
  17. */
  18. const tap = curry((fn, x) => {
  19. fn(x);
  20. return x;
  21. });
  22. module.exports = tap;