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
|
Rev | Line | |
---|
[d24f17c] | 1 | var _curry2 =
|
---|
| 2 | /*#__PURE__*/
|
---|
| 3 | require("./internal/_curry2.js");
|
---|
| 4 |
|
---|
| 5 | var _assertPromise =
|
---|
| 6 | /*#__PURE__*/
|
---|
| 7 | require("./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 |
|
---|
| 40 | var andThen =
|
---|
| 41 | /*#__PURE__*/
|
---|
| 42 | _curry2(function andThen(f, p) {
|
---|
| 43 | _assertPromise('andThen', p);
|
---|
| 44 |
|
---|
| 45 | return p.then(f);
|
---|
| 46 | });
|
---|
| 47 |
|
---|
| 48 | module.exports = andThen; |
---|
Note:
See
TracBrowser
for help on using the repository browser.