1 | var _curry2 =
|
2 | /*#__PURE__*/
|
3 | require("./internal/_curry2");
|
4 |
|
5 | var _assertPromise =
|
6 | /*#__PURE__*/
|
7 | require("./internal/_assertPromise");
|
8 | /**
|
9 | * Returns the result of applying the onFailure function to the value inside
|
10 | * a failed promise. This is useful for handling rejected promises
|
11 | * inside function compositions.
|
12 | *
|
13 | * @func
|
14 | * @memberOf R
|
15 | * @since v0.26.0
|
16 | * @category Function
|
17 | * @sig (e -> b) -> (Promise e a) -> (Promise e b)
|
18 | * @sig (e -> (Promise f b)) -> (Promise e a) -> (Promise f b)
|
19 | * @param {Function} onFailure The function to apply. Can return a value or a promise of a value.
|
20 | * @param {Promise} p
|
21 | * @return {Promise} The result of calling `p.then(null, onFailure)`
|
22 | * @see R.then
|
23 | * @example
|
24 | *
|
25 | * var failedFetch = (id) => Promise.reject('bad ID');
|
26 | * var useDefault = () => ({ firstName: 'Bob', lastName: 'Loblaw' })
|
27 | *
|
28 | * //recoverFromFailure :: String -> Promise ({firstName, lastName})
|
29 | * var recoverFromFailure = R.pipe(
|
30 | * failedFetch,
|
31 | * R.otherwise(useDefault),
|
32 | * R.then(R.pick(['firstName', 'lastName'])),
|
33 | * );
|
34 | * recoverFromFailure(12345).then(console.log)
|
35 | */
|
36 |
|
37 |
|
38 | var otherwise =
|
39 | /*#__PURE__*/
|
40 | _curry2(function otherwise(f, p) {
|
41 | _assertPromise('otherwise', p);
|
42 |
|
43 | return p.then(null, f);
|
44 | });
|
45 |
|
46 | module.exports = otherwise; |
\ | No newline at end of file |