UNPKG

ramda-adjunct

Version:

Ramda Adjunct is the most popular and most comprehensive set of utilities for use with Ramda, providing a variety of useful, well tested functions with excellent documentation.

30 lines (21 loc) 598 B
import { map } from 'ramda'; import resolveP from '../../resolveP'; export class AggregatedError extends Error { constructor(errors = [], message) { super(message); this.errors = errors; } } const anyPolyfill = (iterable) => { const exceptions = []; return new Promise((resolve, reject) => { const onReject = (e) => { exceptions.push(e); if (exceptions.length === iterable.length) { reject(new AggregatedError(exceptions)); } }; map((p) => resolveP(p).then(resolve).catch(onReject), [...iterable]); }); }; export default anyPolyfill;