是否可以更改单子序列?
Is it possible to change monadic sequence?
问题:我有以下Future[Option[T]]
monad,我想应用scalaz Monad Transformer OptionT
到它。因为我只对可选结果感兴趣。
问题:是否可以从Future[Option[T]]
生成Option[Future[T]]
并保留语义?
使用.sequence
:
scala> import scalaz._, Scalaz._, ...
scala> val a: Future[Option[Int]] = Future(None)
a: Future[Option[Int]] = Future(Success(None))
scala> val b = a.sequence
b: Option[Future[Int]] = None
问题:我有以下Future[Option[T]]
monad,我想应用scalaz Monad Transformer OptionT
到它。因为我只对可选结果感兴趣。
问题:是否可以从Future[Option[T]]
生成Option[Future[T]]
并保留语义?
使用.sequence
:
scala> import scalaz._, Scalaz._, ...
scala> val a: Future[Option[Int]] = Future(None)
a: Future[Option[Int]] = Future(Success(None))
scala> val b = a.sequence
b: Option[Future[Int]] = None