从较低种类的类型创建一个 OptionT[Future, A]
Create a OptionT[Future, A] from a lower-kinded type
我是 scalaz 的新手,我正在尝试将各种类型转换为 monad 转换器。
我一直在尝试将 Int
转换为 OptionT[Future, Int]
,甚至 EitherT[Future, String, Int]
。
我找到了一堆 tutorials/SO 解释如何使用 point
执行此操作的答案,但由于某些原因我无法编译它们。
例如,来自 here 的这个片段:
1.point[({ type L[x] = EitherT[Future, String, x] })#L]
Error:(9, 9) could not find implicit value for evidence parameter of type scalaz.Applicative[[x]scalaz.EitherT[scala.concurrent.Future,String,x]]
另一个来自 Scalaz Monad Transformers
type Result[A] = OptionT[Future, A]
"".point[Result]
Error:(8, 10) could not find implicit value for evidence parameter of type scalaz.Applicative[A$A35.this.Result]
我相信这个也应该有效,但它说方法 liftM
不是 Future[Int]
的成员:
1.point[Future].liftM[OptionT] //doesnt compile
1.point[List].liftM[OptionT] //compiles
所有这些示例都失败了,但是如果我将 Future
替换为 List
,它们会编译。现在,这是对我有用的唯一方法,但它有点冗长 - 我真的很想能够使用 point
代替:
OptionT(Future.successful(1.some))
为什么不编译?在最近的版本中,Future
的 applicative/monad 是否已从 scalaz 中删除?
我正在使用 scala 2.11.7 和 scalaz 7.1.3。对于它的价值,这些是我的进口商品:
import scala.concurrent.Future
import scalaz._
import Scalaz._
导入 ExecutionContext
将使您的解决方案编译,请参阅 scalaz.std.scalaFuture
。
import scala.concurrent.ExecutionContext.Implicits.global
type Result[A] = OptionT[Future, A]
"".point[Result]
// Result[String] = OptionT(scala.concurrent.impl.Promise$DefaultPromise@5e155fc)
1.point[Future].liftM[OptionT]
// scalaz.OptionT[scala.concurrent.Future,Int] = OptionT(scala.concurrent.impl.Promise$DefaultPromise@60821af9)
我是 scalaz 的新手,我正在尝试将各种类型转换为 monad 转换器。
我一直在尝试将 Int
转换为 OptionT[Future, Int]
,甚至 EitherT[Future, String, Int]
。
我找到了一堆 tutorials/SO 解释如何使用 point
执行此操作的答案,但由于某些原因我无法编译它们。
例如,来自 here 的这个片段:
1.point[({ type L[x] = EitherT[Future, String, x] })#L]
Error:(9, 9) could not find implicit value for evidence parameter of type
scalaz.Applicative[[x]scalaz.EitherT[scala.concurrent.Future,String,x]]
另一个来自 Scalaz Monad Transformers
type Result[A] = OptionT[Future, A]
"".point[Result]
Error:(8, 10) could not find implicit value for evidence parameter of type
scalaz.Applicative[A$A35.this.Result]
我相信这个也应该有效,但它说方法 liftM
不是 Future[Int]
的成员:
1.point[Future].liftM[OptionT] //doesnt compile
1.point[List].liftM[OptionT] //compiles
所有这些示例都失败了,但是如果我将 Future
替换为 List
,它们会编译。现在,这是对我有用的唯一方法,但它有点冗长 - 我真的很想能够使用 point
代替:
OptionT(Future.successful(1.some))
为什么不编译?在最近的版本中,Future
的 applicative/monad 是否已从 scalaz 中删除?
我正在使用 scala 2.11.7 和 scalaz 7.1.3。对于它的价值,这些是我的进口商品:
import scala.concurrent.Future
import scalaz._
import Scalaz._
导入 ExecutionContext
将使您的解决方案编译,请参阅 scalaz.std.scalaFuture
。
import scala.concurrent.ExecutionContext.Implicits.global
type Result[A] = OptionT[Future, A]
"".point[Result]
// Result[String] = OptionT(scala.concurrent.impl.Promise$DefaultPromise@5e155fc)
1.point[Future].liftM[OptionT]
// scalaz.OptionT[scala.concurrent.Future,Int] = OptionT(scala.concurrent.impl.Promise$DefaultPromise@60821af9)