I am trying to help someone in StackOverflow with a question regarding Futures and Maybes and Eithers. My first approach is to have a simple function that takes in a Maybe
and computes something.
I am using Sanctuary, but this is equivalent to Ramda or any other library.
const S = require("sanctuary");
const transform = S.map(
S.pipe( [ S.trim, S.toUpper ] )
);
S.Maybe.Just( [" heello", " world!"] )
.map( transform )
The problem is that this simple function is failing with the error:
TypeError: S.Maybe.Just(...).map is not a function
I am confused to say the least. I know that Maybe is a Monad, and that Monads are Functors. Each Functor must have a map
method, but somehow Maybe.Just ( which is a Maybe type ) doesn't?
What am I doing wrong?
Maybe
is a functor and has a fantasy-land/map
attached, and it's consumed using S.map
. Also, you build a Just
using S.Just
or S.of (S.Maybe)
:
const S = require("sanctuary");
const transform = S.pipe ([ S.trim, S.toUpper ])
const maybeTransformed = S.map (transform) (S.Just (['hello', ' world!']))