Converts a nullable value to a Validation
. null
and undefined
map to Failure
s, any other type maps to Success
es.
forall a, b:
(a or None, b) => Validation b a
Converts a nullable value to a Validation
. null
and undefined
map to Failure
s, any other type maps to Success
es.
A nullable is a value that may be any type, or null
/undefined
.
const nullableToValidation = require('folktale/conversions/nullable-to-validation');
const { Failure, Success } = require('folktale/validation');
nullableToValidation(undefined, 'error');
// ==> Failure('error')
nullableToValidation(null, 'error');
// ==> Failure('error')
nullableToValidation(1, 'error');
// ==> Success(1)
(a, fallbackValue) =>
a != null ? Success(a)
:/*else*/ Failure(fallbackValue)