Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

otherwise

v0.26.1arrow_drop_down
v0.26.1
STATUS
Passing
DOWNLOADS
3
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
7 months ago
SIZE
4 KB
subject
Returns the result of applying the onFailure function to the value inside a failed promise.
1 contributor
Use otherwise in your project ?
Copied
npm i @bit/ramda.ramda.otherwise
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
Component Example
React
React
Vue
Angular
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';
revert changes
reload
toggle layout
maximize
Promise.reject("bad ID");
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)`