I was wondering if there is a way to turn List[Kleisli[Option, Int, Int]]
to Kleisli[Option, Int, List[Int]]
.
In particular I have the list of kleisli formed like this:
def k(a: String) = Kleisli[Option, Int, Int](m => Some(a.length * m))
val kList = List("hi", "hello").map(k)
What I do is the following
Kleisli[Option, Int, List[Int]](m => kList.map(_.run(m)).sequence)
which is very messy, not expressive and requires a lot of manual work.
Is there a better way?