Scala:元组的并行赋值
是否可以在 Scala 中并行分配元组成员。如果没有,是否有另一种技术可以完成类似的事情?
val players = List(
new Player("Django Reinhardt", 42),
new Player("Sol Hoopii", 57),
new Player("Marc Ribot", 64)
)
val winners, losers = players.partition(p => p.score > 50)
// winners = List(Player name:Sol Hoopii score: 57, Player name:Marc Ribot score: 64)
// losers = List(Player name:Django Reinhardt score: 42)
Is it possible to assign tuple members in parallel in Scala. if not is there another technique to accomplish something similar?
val players = List(
new Player("Django Reinhardt", 42),
new Player("Sol Hoopii", 57),
new Player("Marc Ribot", 64)
)
val winners, losers = players.partition(p => p.score > 50)
// winners = List(Player name:Sol Hoopii score: 57, Player name:Marc Ribot score: 64)
// losers = List(Player name:Django Reinhardt score: 42)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 (List, List) 元组分配给两个变量。如果你想解压元组,你必须使用
Which 完全符合你的要求。 :-)
Assignes the (List, List) tuple to two variables. If you want to unpack the tuple you have to use
Which does exactly what you want. :-)