当我不关心返回值时,应该如何编写代码。
示例:
for {
a <- getA // I do not care about a, but I need to wait for the future to finish
b <- getB
} yield (b)
当我不关心返回值时,应该如何编写代码。
示例:
for {
a <- getA // I do not care about a, but I need to wait for the future to finish
b <- getB
} yield (b)
像这样
for {
_ <- getA
b <- getB
} yield (b)
getA.flatMap(_ => getB )
但我认为大多数人会投票支持理解
getA.flatMap(_ => getB)
就足够了(对于任何合理的情况,getB.map(identity)
的行为应该与 getB
相同)。 - Alexey Romanov
_ <- getA
来强调你不关心getA
的结果,但从功能上讲,它们是相同的。 - Michael Zajac