pawel.panasewicz - 6 months ago 51

Scala Question

Given a function with signature:

`A => F[G[B]]`

`F`

`G`

Is it possible to transform it into something with the signature:

`F[G[A=>B]`

In other words what would be the implementation of

`prettify2`

`def pretiffy(x: String): Future[Option[String]] = Future{if(x == "") None else Some(s">>>$x<<<")}`

val pretiffy2: Future[Option[String => String]] = ???

Update: I'd appreciate answers using cats or scalaz.

Answer

Suppose we have a `String=>List[Option[Integer]]`

. We need to produce a `List[Option[String=>Integer]]`

. How should we approach this? For example, how long the resulting list should be? How many `None`

s should it contain?

Obviously these questions have no answers, which means the requested transformation cannot exist for an arbitrary monad (or indeed most monads, as one can ask similar questions about most monads).