nullableToValidation

Converts a nullable value to a Validation. null and undefined map to Failures, any other type maps to Successes.

Signature

nullableToValidation(a, fallbackValue)
forall a, b:
  (a or None, b) => Validation b a

Documentation

Converts 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.

Example:

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)

Properties

Source Code

Defined in source/conversions/nullable-to-validation.js at line 22, column 0
(a, fallbackValue) =>
  a != null ?  Success(a)
  :/*else*/    Failure(fallbackValue)
Stability
stable
Licence
MIT
Module
folktale/conversions/nullable-to-validation
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • @boris-marinov
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)