A convenience method for the folktale/conversions/nullable-to-result
module.
forall a, b: (a or None, b) => Result b a
| (a or None) => Result None a
A convenience method for the folktale/conversions/nullable-to-result
module.
DEPRECATION WARNING:
In 2.0.x,fromNullable
took only one parameter. This form of the method is now deprecated in favour of passing an explicit fallback value.
const Result = require('folktale/result');
Result.fromNullable(1, 'error');
// ==> Result.Ok(1)
Result.fromNullable(null, 'error');
// ==> Result.Error('error')
Result.fromNullable(undefined, 'error');
// ==> Result.Error('error')
fromNullable(aNullable, fallbackValue) {
const nullableToResult = require('folktale/conversions/nullable-to-result');
if (arguments.length > 1) { // eslint-disable-line prefer-rest-params
return nullableToResult(aNullable, fallbackValue);
} else {
return nullableToResult(aNullable);
}
}