source: node_modules/ramda/src/otherwise.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[d24f17c]1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2.js");
4
5var _assertPromise =
6/*#__PURE__*/
7require("./internal/_assertPromise.js");
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.andThen
23 * @example
24 *
25 * const failedFetch = id => Promise.reject('bad ID');
26 * const useDefault = () => ({ firstName: 'Bob', lastName: 'Loblaw' });
27 *
28 * //recoverFromFailure :: String -> Promise ({ firstName, lastName })
29 * const recoverFromFailure = R.pipe(
30 * failedFetch,
31 * R.otherwise(useDefault),
32 * R.andThen(R.pick(['firstName', 'lastName'])),
33 * );
34 * recoverFromFailure(12345).then(console.log);
35 */
36
37
38var otherwise =
39/*#__PURE__*/
40_curry2(function otherwise(f, p) {
41 _assertPromise('otherwise', p);
42
43 return p.then(null, f);
44});
45
46module.exports = otherwise;
Note: See TracBrowser for help on using the repository browser.