我如何for理解类型的数据Future[\/[String,Int]]
这是一个起点,不编译.
import scala.concurrent.{ExecutionContext,future,Future}
import scalaz._
import Scalaz._
import ExecutionContext.Implicits.global
def calculateStuff(i:Int):Future[\/[String,Int]] = future{\/-(i)}
for {
v1Either <- calculateStuff(1)
v1Int <- v1Either
v2Either < calculateStuff(v1Int)
v2Int <- v2Either
v3Either <- calculateStuff(v2Int)
v3Int <- v3Either
} yield {
v1Int + v2Int + v3Int
}
Run Code Online (Sandbox Code Playgroud)
注意:calculateStuff只是一个例子,实际上会有不同的功能,每个功能都取决于前一个的结果.