source: node_modules/ramda/es/andThen.js

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 
1import _curry2 from "./internal/_curry2.js";
2import _assertPromise from "./internal/_assertPromise.js";
3/**
4 * Returns the result of applying the onSuccess function to the value inside
5 * a successfully resolved promise. This is useful for working with promises
6 * inside function compositions.
7 *
8 * @func
9 * @memberOf R
10 * @since v0.27.1
11 * @category Function
12 * @sig (a -> b) -> (Promise e a) -> (Promise e b)
13 * @sig (a -> (Promise e b)) -> (Promise e a) -> (Promise e b)
14 * @param {Function} onSuccess The function to apply. Can return a value or a promise of a value.
15 * @param {Promise} p
16 * @return {Promise} The result of calling `p.then(onSuccess)`
17 * @see R.otherwise
18 * @example
19 *
20 * const makeQuery = email => ({ query: { email }});
21 * const fetchMember = request =>
22 * Promise.resolve({ firstName: 'Bob', lastName: 'Loblaw', id: 42 });
23 *
24 * //getMemberName :: String -> Promise ({ firstName, lastName })
25 * const getMemberName = R.pipe(
26 * makeQuery,
27 * fetchMember,
28 * R.andThen(R.pick(['firstName', 'lastName']))
29 * );
30 *
31 * getMemberName('bob@gmail.com').then(console.log);
32 */
33
34var andThen =
35/*#__PURE__*/
36_curry2(function andThen(f, p) {
37 _assertPromise('andThen', p);
38
39 return p.then(f);
40});
41
42export default andThen;
Note: See TracBrowser for help on using the repository browser.