gpt4 book ai didi

scala - 如何在 scalaz 中编写 monad 转换器

转载 作者:行者123 更新时间:2023-12-02 04:51:09 24 4
gpt4 key购买 nike

如何进行编译,或做类似的事情?

import scala.concurrent.Future
import scalaz._
import Scalaz._

val ee: Future[Unit \/ Option[Int]] = Future(\/-(Option(1)))
OptionT.optionT(EitherT.eitherT(ee))

最佳答案

您只需要显式传递类型(OptionT.optionT 似乎做了一些稍微不同的事情):

//could use a type lambda, but this is (IMO) slightly clearer
type FutureEither[A] = EitherT[Future, Unit, A]
new OptionT[FutureEither, Int](EitherT.eitherT[Future, Unit, Option[Int]](ee))

(我可能应该提到我的 scalaz-transfigure 库,它是一种更轻量级和更推理的方法,可以做与 monad 转换器相同的事情;尽管它还不是很成熟)

关于scala - 如何在 scalaz 中编写 monad 转换器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28200759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com