This is a simple example of use of a mysterious beast called a Kleisli arrow.
I will be using scalaz for my incantations as it comes with the necessary potions.
What is the Problem?
You have functions that take a simple type and return higher kinded types like Options or Lists, and you need to compose those functions. You might think you need to get the first result, pattern match on the it, apply it to the second function, repeat. Sounds rather cumbersome.
The intuition is this:
a Kleisli is function composition for Monads.
Hmm, lets try again:
if you have functions that return kinds of things, like Lists, Options, etc,
then you can use a Kleisli to compose those functions.
I was asked by bhericher below about composing functions returning different types. Here is a solution but I am not sure if its the best way:
Please review our Community Guidelines before posting a comment. We encourage discussion in good faith, but do not allow combabitive, exclusionary, or harassing behaviour. If you have any questions, contact us!