In fantasy-land spec, the signature for ap
method is defined as
fantasy-land/ap :: Apply f => f a ~> f (a -> b) -> f b
This translates as: The container f with value a
has a method ap
which takes a parameter container f
with value of a function (a ->b)
and returns a container f with value b
. I hope I am right in this interpretation.
If I test this with Folktale, However I see different results:
const Maybe = require("data.maybe")
Maybe.of(5).ap(Maybe.of(x => x + 1)) // Uncaught TypeError: f is not a function
Maybe.of(x=>x+1).ap(Maybe.of(5)) // Maybe { value: 6 }
Maybe.of(x=>x+1).ap(Either.of(5)) // Either { value: 6 }
If I test this with Sanctuary, I see similar results (though Sanctuary does not have it as a "method")
const S = require("sanctuary")
let a = S.of(S.Maybe)(5)
let fn = S.of(S.Maybe)(x => x + 1)
S.ap(fn)(a) // Just (6)
S.ap(a)(fn) // Uncaught TypeError: Invalid value
This brings me to the conclusion that perhaps the fantasy-land specs for ap
method could be:
fantasy-land/ap :: Apply f => f (a -> b) ~> f a -> f b
I am a newbie on FP and fantasy-land as well. I am happy to get corrected :)