Ramda Adjunct 2.33.0

anyP.js

  1. import { bind, curryN } from 'ramda';
  2. import isFunction from './isFunction';
  3. import ponyfill, { AggregatedError } from './internal/ponyfills/Promise.any';
  4. export const anyPPonyfill = curryN(1, ponyfill);
  5. export { AggregatedError };
  6. /**
  7. * Returns a promise that is fulfilled by the first given promise to be fulfilled,
  8. * or rejected with an array of rejection reasons if all of the given promises are rejected.
  9. *
  10. * @func anyP
  11. * @memberOf RA
  12. * @category Function
  13. * @since {@link https://char0n.github.io/ramda-adjunct/2.22.0|v2.22.0}
  14. * @sig [Promise a] -> Promise a
  15. * @param {Iterable.<*>} iterable An iterable object such as an Array or String
  16. * @return {Promise} A promise that is fulfilled by the first given promise to be fulfilled, or rejected with an array of rejection reasons if all of the given promises are rejected
  17. * @see {@link RA.lastP|lastP}
  18. * @example
  19. *
  20. * RA.anyP([
  21. * Promise.resolve(1),
  22. * 2,
  23. * Promise.reject(3),
  24. * ]); //=> Promise(1)
  25. */
  26. const anyP = isFunction(Promise.any)
  27. ? curryN(1, bind(Promise.any, Promise))
  28. : anyPPonyfill;
  29. export default anyP;