unsafeGet

Extracts the value from a Validation structure.

Signature

forall a, b: (Validation a b).() => b :: throws TypeError

Documentation

Extracts the value from a Validation structure.

WARNING
This method is partial, which means that it will only work for Success structures, not for Failure structures. It's recommended to use .getOrElse() or .matchWith() instead.

Example:

const { Failure, Success } = require('folktale/validation');

Success('a').unsafeGet();
// ==> 'a'


try {
  Failure('a').unsafeGet();
  // TypeError: Can't extract the value of an Error
} catch (e) {
  e instanceof TypeError; // ==> true
}

Properties

Source Code

Defined in source/validation/validation.js at line 70, column 23
{
    /*~*/
    Failure: function unsafeGet() {
      throw new TypeError(`Can't extract the value of a Failure.

    Failure does not contain a normal value - it contains an error.
    You might consider switching from Validation#get to Validation#getOrElse, or some other method
    that is not partial.
      `);
    },

    /*~*/
    Success: function unsafeGet() {
      return this.value;
    }
  }
Licence
MIT
Module
folktale/validation/validation
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)