pawel.panasewicz pawel.panasewicz - 1 year ago 90
Scala Question

transform 'A => F[G[B]]' into 'F[G[A=>B]' scala

Given a function with signature:

A => F[G[B]]
. There are monads instances for

Is it possible to transform it into something with the signature:
? Is there any general name for such transformation?

In other words what would be the implementation of

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 Source

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 Nones 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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download