Converts a nullable value to a Validation. null and undefined
map to Failures, any other type maps to Successes.
forall a, b:
(a or None, b) => Validation b aConverts a nullable value to a Validation. null and undefined
map to Failures, any other type maps to Successes.
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)