[英]What type of expression is this in scala?
Considering x,p,r are evaluated from the previous expressions, what is happening underneath, <- and then after =考虑到 x,p,r 是从前面的表达式中计算出来的,下面发生了什么,<- 然后在 =
val a = for{
x <- y
p = q (x)
r <- s (p)
} yield (something(p.something, r.something))
The <-
is equivalent (syntactic sugar) to .flatMap
call, while =
is equivalent to val x =
(and yield
kind of final .map
). <-
等效于.flatMap
调用(语法糖),而=
等效于val x =
(并yield
最终的.map
)。
So the code is equivalent to:所以代码等价于:
val a = y.flatMap { x => // first <-
val p = q (x)
s(p).map { r => // 2nd <- + yield
something(p.something, r.something)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.