unsafeGet

Extracts the value from a Result structure.

Signature

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

Documentation

Extracts the value from a Result structure.

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

Example:

const Result = require('folktale/result');

Result.Ok(1).unsafeGet();
// ==> 1


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

Properties

Source Code

Defined in source/result/result.js at line 75, column 19
{
    /*~*/
    Error: function unsafeGet() {
      throw new TypeError(`Can't extract the value of an Error.

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

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