I'm using ramda-fantasy
for the monads. I have a string inside a maybe and a some functions that will perform regex matches on a string and return a Maybe String
.
How do I map the maybe to apply all of the functions and concatenate the result?
I have
const fieldRetrievers = [
getAddress,
getName,
getPhone,
]
const text = Maybe.of("a text")
// I want to define
// List (String -> Maybe String) -> Maybe String -> Maybe String
function getInfo(retrievers, maybeText) {...}
How can I do that?
You're looking for
composeK
, the function composition over monadic structures ("kleisli arrows").Basically, your resulting function is supposed to repeatedly
chain
onto the input:which you could implement using a
reduce
over your array of functions:so you'd write