简体   繁体   English

将'A => F [G [B]]'转换为'F [G [A => B]'标量

[英]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. FG类型的单子实例。

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.

相关问题 Scala如何将Seq [(((A,B,C,D),Seq [(E,F,G)])]]转换为Seq [(A,B,C,D,Seq [(E,F,G) ])]? - Scala How to transform Seq[((A, B, C, D), Seq[(E, F, G)])] to Seq[(A, B, C, D, Seq[(E, F, G)])]? def compose [A,B,C](f:B =&gt; C,g:A =&gt; B):A =&gt; C = {f(g(_))}是不是有效的Scala声明? - def compose[A,B,C](f: B => C, g: A => B): A => C = {f(g(_))} is noty valid scala declaration? Scalaz monad变形金刚。 将f1:A =&gt; G [B],f2:B =&gt; G [C]函数应用于F [G [A]]对象 - Scalaz monad transformers. Applying f1:A => G[B], f2:B => G[C] function to F[G[A]] object Scala中f(a,b)和f(a)(b)之间的差异 - Difference between f(a,b) and f(a)(b) in Scala 如何将F [Either [A,B]]转换为Either [F [A],F [B]] - How to transform F[Either[A, B]] to Either[F[A], F[B]] 如何将F [A \\ / B]拆分为(F [A],F [B]) - How to split F[A \/ B] into (F[A], F[B]) 在Scala(猫或scalaz)中转换仿函数(F [A] => G [A]) - Converting functors (F[A] => G[A]) in Scala (cats or scalaz) Scala中Array.map(f:A =&gt; B)的性能不佳 - Poor performance of Array.map(f: A => B) in Scala Scala-使依赖于g的变量的高阶函数g的函数参数f签名 - Scala - Make signature of function parameter f of higher order function g dependent on varars of g 函数等价于if(p(f(a),f(b))a else b - Functional equivalent of if (p(f(a), f(b)) a else b
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM