validationToMaybe

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

Signature

validationToMaybe(aValidation)
forall a, b:
  (Validation a b) => Maybe b

Documentation

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

Failure values are lost in the process, since the Nothing tag can't hold any values.

Example:

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

validationToMaybe(Failure(1));  // ==> Nothing()
validationToMaybe(Success(1));  // ==> Just(1)

Properties

Source Code

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