source: node_modules/ramda/src/andThen.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
Line 
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 onSuccess function to the value inside
10 * a successfully resolved promise. This is useful for working with promises
11 * inside function compositions.
12 *
13 * @func
14 * @memberOf R
15 * @since v0.27.1
16 * @category Function
17 * @sig (a -> b) -> (Promise e a) -> (Promise e b)
18 * @sig (a -> (Promise e b)) -> (Promise e a) -> (Promise e b)
19 * @param {Function} onSuccess 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(onSuccess)`
22 * @see R.otherwise
23 * @example
24 *
25 * const makeQuery = email => ({ query: { email }});
26 * const fetchMember = request =>
27 * Promise.resolve({ firstName: 'Bob', lastName: 'Loblaw', id: 42 });
28 *
29 * //getMemberName :: String -> Promise ({ firstName, lastName })
30 * const getMemberName = R.pipe(
31 * makeQuery,
32 * fetchMember,
33 * R.andThen(R.pick(['firstName', 'lastName']))
34 * );
35 *
36 * getMemberName('bob@gmail.com').then(console.log);
37 */
38
39
40var andThen =
41/*#__PURE__*/
42_curry2(function andThen(f, p) {
43 _assertPromise('andThen', p);
44
45 return p.then(f);
46});
47
48module.exports = andThen;
Note: See TracBrowser for help on using the repository browser.