maybeToResult

Converts a Maybe to an Result. Nothings map to Errors, Justs map to Oks.

Signature

maybeToResult(aMaybe, failureValue)
forall a, b:
  (Maybe a, b) => Result b a

Documentation

Converts a Maybe to an Result. Nothings map to Errors, Justs map to Oks.

Note that since Maybes don't hold a value for failures in the Nothing tag, you must provide one to this function.

Example:

const maybeToResult = require('folktale/conversions/maybe-to-result');
const { Error, Ok } = require('folktale/result');
const { Nothing, Just } = require('folktale/maybe');

maybeToResult(Nothing(), 2); // ==> Error(2)
maybeToResult(Just(1), 2);   // ==> Ok(1)

Properties

Source Code

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