promap.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import _curry3 from "./internal/_curry3.js";
  2. import _dispatchable from "./internal/_dispatchable.js";
  3. import _promap from "./internal/_promap.js";
  4. import _xpromap from "./internal/_xpromap.js";
  5. /**
  6. * Takes two functions as pre- and post- processors respectively for a third function,
  7. * i.e. `promap(f, g, h)(x) === g(h(f(x)))`.
  8. *
  9. * Dispatches to the `promap` method of the third argument, if present,
  10. * according to the [FantasyLand Profunctor spec](https://github.com/fantasyland/fantasy-land#profunctor).
  11. *
  12. * Acts as a transducer if a transformer is given in profunctor position.
  13. *
  14. * @func
  15. * @memberOf R
  16. * @since v0.28.0
  17. * @category Function
  18. * @sig (a -> b) -> (c -> d) -> (b -> c) -> (a -> d)
  19. * @sig Profunctor p => (a -> b) -> (c -> d) -> p b c -> p a d
  20. * @param {Function} f The preprocessor function, a -> b
  21. * @param {Function} g The postprocessor function, c -> d
  22. * @param {Profunctor} profunctor The profunctor instance to be promapped, e.g. b -> c
  23. * @return {Profunctor} The new profunctor instance, e.g. a -> d
  24. * @see R.transduce
  25. * @example
  26. *
  27. * const decodeChar = R.promap(s => s.charCodeAt(), String.fromCharCode, R.add(-8))
  28. * const decodeString = R.promap(R.split(''), R.join(''), R.map(decodeChar))
  29. * decodeString("ziuli") //=> "ramda"
  30. *
  31. * @symb R.promap(f, g, h) = x => g(h(f(x)))
  32. * @symb R.promap(f, g, profunctor) = profunctor.promap(f, g)
  33. */
  34. var promap =
  35. /*#__PURE__*/
  36. _curry3(
  37. /*#__PURE__*/
  38. _dispatchable(['fantasy-land/promap', 'promap'], _xpromap, _promap));
  39. export default promap;