resultToMaybe

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

Signature

resultToMaybe(aResult)
forall a, b:
  (Result a b) => Maybe b

Documentation

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

Not that Error values are lost in the conversion process, since failures in Maybe (the Nothing tag) don't have a value.

Example:

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

resultToMaybe(Error(1));  // ==> Nothing()
resultToMaybe(Ok(1)); // ==> Just(1) 

Properties

Source Code

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