【发布时间】:2018-10-23 09:08:33
【问题描述】:
我正在将一些代码从 Ruby 转换为 Scala。问题是我一生中从未编写过 Ruby。进展顺利,但现在我到达了一条我不知道的线,因为我是 Scala 的新手,我不了解排序机制。 所以我想把这条红宝石线翻译成scala:
fronts[last_front].sort! {|x,y| crowded_comparison_operator(x,y)}
fronts 是Vector[Vector[Map[String, Any]]]
last_front 是Int
crowded_comparison_operator(x,y) 返回 -1、0 或 1,x 和 y 为 Map[String, Any]
【问题讨论】:
-
你看过the docs for sortBy吗?
-
当然,但是
crowded_comparison_operator(x,y)需要两个参数,这让我很困惑。对不起,我在 Scala/Java 中有点菜鸟
标签: ruby scala sorting translate code-translation