unsafeGet

Extracts the value from a Just structure.

Signature

forall a: (Maybe a).() => a :: (throws TypeError)

Documentation

Extracts the value from a Just structure.

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

Example:

const Maybe = require('folktale/maybe');

Maybe.Just(1).unsafeGet(); // ==> 1

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

Properties

Source Code

Defined in source/maybe/maybe.js at line 57, column 18
{
    /*~*/
    Nothing: function unsafeGet() {
      throw new TypeError(`Can't extract the value of a Nothing.

    Since Nothing holds no values, it's not possible to extract one from them.
    You might consider switching from Maybe#get to Maybe#getOrElse, or some other method
    that is not partial.
      `);
    },

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