maybeToValidation

Converts a Maybe to a Validation. Nothings map to Failures, Justs map to Successes.

Signature

maybeToValidation(aMaybe, failureValue)
forall a, b:
  (Maybe a, b) => Validation b a

Documentation

Converts a Maybe to a Validation. Nothings map to Failures, Justs map to Successes.

Note that since Maybe failures can't hold a value in the Nothing tag, you must provide one for the validation.

Example:

const maybeToValidation = require('folktale/conversions/maybe-to-validation');
const { Failure, Success } = require('folktale/validation');
const { Nothing, Just } = require('folktale/maybe');

maybeToValidation(Nothing(), 2);  // ==> Failure(2)
maybeToValidation(Just(1), 2);    // ==> Success(1)

Properties

Source Code

Defined in source/conversions/maybe-to-validation.js at line 22, column 0
(aMaybe, failureValue) =>
  aMaybe.matchWith({
    Nothing: () => Failure(failureValue),
    Just:    ({ value }) => Success(value)
  })
Stability
stable
Licence
MIT
Module
folktale/conversions/maybe-to-validation
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • @boris-marinov
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)