[英]transform 'A => F[G[B]]' into 'F[G[A=>B]' scala
Given a function with signature: A => F[G[B]]
. 给定带签名的函数: A => F[G[B]]
。 There are monads instances for F
and G
types. 有F
和G
类型的单子实例。
Is it possible to transform it into something with the signature: F[G[A=>B]
? 是否可以将其转换为带有签名的东西: F[G[A=>B]
? Is there any general name for such transformation? 这样的转换有什么通用名称吗?
In other words what would be the implementation of prettify2
? 换句话说, 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. 更新:我希望使用猫或斯卡拉兹回答。
Suppose we have a String=>List[Option[Integer]]
. 假设我们有一个String=>List[Option[Integer]]
。 We need to produce a List[Option[String=>Integer]]
. 我们需要产生一个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? 它应包含多少个None
?
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). 显然,这些问题没有答案,这意味着所请求的转换不能存在于任意一个monad(或者实际上是大多数monad,因为人们可以对大多数monad提出类似的问题)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.