main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
1.3 KB
|
Line | |
---|
1 | import { curryN, map, pipe } from 'ramda';
|
---|
2 |
|
---|
3 | import allP from './allP';
|
---|
4 | import rejectP from './rejectP';
|
---|
5 | import resolveP from './resolveP';
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Returns a Promise that is resolved with an array of reasons when all of the provided Promises reject, or rejected when any Promise is resolved.
|
---|
9 | * This pattern is like allP, but fulfillments and rejections are transposed - rejections become the fulfillment values and vice versa.
|
---|
10 | *
|
---|
11 | * @func noneP
|
---|
12 | * @memberOf RA
|
---|
13 | * @since {@link https://char0n.github.io/ramda-adjunct/2.22.0|v2.22.0}
|
---|
14 | * @category Function
|
---|
15 | * @sig [Promise a] -> Promise [a]
|
---|
16 | * @param {Iterable.<*>} iterable An iterable object such as an Array or String
|
---|
17 | * @return {Promise} A Promise that is resolved with a list of rejection reasons if all Promises are rejected, or a Promise that is rejected with the fulfillment value of the first Promise that resolves.
|
---|
18 | * @see {@link RA.allP|allP}
|
---|
19 | * @example
|
---|
20 | *
|
---|
21 | * RA.noneP([Promise.reject('hello'), Promise.reject('world')]); //=> Promise(['hello', 'world'])
|
---|
22 | * RA.noneP([]); //=> Promise([])
|
---|
23 | * RA.noneP([Promise.reject(), Promise.resolve('hello world')]); //=> Promise('hello world')
|
---|
24 | * RA.noneP([Promise.reject(), 'hello world']); //=> Promise('hello world')
|
---|
25 | */
|
---|
26 | const noneP = curryN(
|
---|
27 | 1,
|
---|
28 | pipe(
|
---|
29 | map(resolveP),
|
---|
30 | map((p) => p.then(rejectP, resolveP)),
|
---|
31 | allP
|
---|
32 | )
|
---|
33 | );
|
---|
34 |
|
---|
35 | export default noneP;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.