How to use the otherwise function from ramda

Find comprehensive JavaScript ramda.otherwise code examples handpicked from public code repositorys.

3
4
5
6
7
8
9
10
11
12
const useDefault = () => ({ firstName: 'Bob', lastName: 'Loblaw' });


//recoverFromFailure :: String -> Promise ({ firstName, lastName })
const recoverFromFailure = R.pipe(
    failedFetch,  // solve -> to andThen
    R.otherwise(useDefault),
    R.andThen(R.pick(['firstName', 'lastName'])),
);
recoverFromFailure(12345).then(console.log);
fork icon0
star icon1
watch icon0

555
556
557
558
559
560
561
562
563
564
* @sig (a -> b) -> (Promise e a) -> (Promise e b)
* @sig (a -> (Promise e b)) -> (Promise e a) -> (Promise e b)
* @param {Function} onSuccess The function to apply. Can return a value or a promise of a value.
* @param {Promise} p
* @return {Promise} The result of calling `p.then(onSuccess)`
* @see R.otherwise
* @example
*
*      var makeQuery = (email) => ({ query: { email }});
*
fork icon0
star icon0
watch icon2

+ 7 other calls in file

Other functions in ramda

Sorted by popularity

function icon

ramda.clone is the most popular function in ramda (30311 examples)