Ramda Adjunct 2.33.0

thenCatchP.js

  1. import { invoker } from 'ramda';
  2. /**
  3. * Composable shortcut for `Promise.then` that allows for success and failure callbacks.
  4. * The thenCatchP function returns a Promise. It takes three arguments: a callback function for the success of the Promise,
  5. * a callback function for the failure of the Promise, and the promise instance itself.
  6. *
  7. * @func thenCatchP
  8. * @memberOf RA
  9. * @since {@link https://char0n.github.io/ramda-adjunct/2.27.0|v2.27.0}
  10. * @category Function
  11. * @sig (a -> b) -> (c -> d) -> Promise a -> Promise b | d
  12. * @param {Function} onFulfilled A Function called if the Promise is fulfilled. This function has one argument, the fulfillment value
  13. * @param {Function} onRejected A Function called if the Promise is rejected. This function has one argument, the error
  14. * @param {Promise} promise Any Promise or Thenable object
  15. * @return {Promise}
  16. * @see {@link RA.resolveP|resolveP}, {@link RA.rejectP|rejectP}, {@link RA.allP|allP}
  17. * @example
  18. *
  19. * const promise = Promise.resolve(1);
  20. * const add1 = x => x + 1;
  21. *
  22. * RA.thenCatchP(add1, console.error, promise); // => Promise(2)
  23. */
  24. export const thenCatchP = invoker(2, 'then');
  25. export default thenCatchP;