UNPKG

1.15 kBJavaScriptView Raw
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2");
4
5var _assertPromise =
6/*#__PURE__*/
7require("./internal/_assertPromise");
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.0
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 * var makeQuery = (email) => ({ query: { email }});
26 *
27 * //getMemberName :: String -> Promise ({firstName, lastName})
28 * var getMemberName = R.pipe(
29 * makeQuery,
30 * fetchMember,
31 * R.andThen(R.pick(['firstName', 'lastName']))
32 * );
33 */
34
35
36var andThen =
37/*#__PURE__*/
38_curry2(function andThen(f, p) {
39 _assertPromise('andThen', p);
40
41 return p.then(f);
42});
43
44module.exports = andThen;
\No newline at end of file