otherwise

v0.9.6arrow_drop_down
v0.9.6
STATUS
Passing
DOWNLOADS
2
VISIBILITY
Public
PUBLISHED
5 years ago
SIZE
4 KB
Returns the result of applying the onFailure function to the value inside a failed promise.
1 contributor
Install otherwise as a package?
Copied
npm i @bit/justin-capalbo.ramda.otherwise
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.cloud
Component Example
React
React
Vue
Angular
React Native
Add dependency... help_outline
Just
import
any of the 1 million components
and packages in Bit or NPM to the example.
import Button from '@bit/grommet.grommet.button';
import Lodash from 'lodash';
toggle layout
No preview available
modifieddraft
chevron_left
chevron_right
otherwise (
onFailure:Function,
p:Promise
) : Promise

Returns the result of applying the onFailure function to the value inside a failed promise. This is useful for handling rejected promises inside function compositions.

Example
var failedFetch = (id) => Promise.reject('bad ID');
     var useDefault = () => ({ firstName: 'Bob', lastName: 'Loblaw' })

     //recoverFromFailure :: String -> Promise ({firstName, lastName})
     var recoverFromFailure = R.pipe(
       failedFetch,
       R.otherwise(useDefault),
       R.then(R.pick(['firstName', 'lastName'])),
     );
     recoverFromFailure(12345).then(console.log)
Arguments
onFailure: Function

The function to apply. Can return a value or a promise of a value.

p: Promise
Returns
Promise

The result of calling `p.then(null, onFailure)`

Help and resources