Converts a Maybe to an Result. Nothings map to Errors, Justs map to
Oks.
forall a, b:
(Maybe a, b) => Result b aConverts 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.
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)
(aMaybe, failureValue) =>
aMaybe.matchWith({
Nothing: () => Error(failureValue),
Just: ({ value }) => Ok(value)
})