val deck = 1 to 52 toList
// shuffles the deck, and prints it out nicely
deck sortWith ((_, _) => Random.nextBoolean) foreach (x => print(x + " "))
由于我将一遍又一遍地洗牌和打印甲板,我正在尝试执行以下操作
val deck = 1 to 52 toList
def shuffle : (List[Int] => List[Int]) = {_ sortWith ((_, _) => Random.nextBoolean)}
def printDeck : (List[Int] => Unit) = {_ foreach(x => print(x + " "))}
deck shuffle printDeck // this doesnt work
// I can only do
printDeck(shuffle(deck)) // this works
当您不必使用括号时,调用参数左侧的函数会更加优雅。