在“Simply Lift”REST 示例中我们可以找到
case Nil JsonGet _ => Item.inventoryItems: JValue
但是
case Nil JsonPut Item(item) -> _ => Item.add(item): JValue
为什么是 -> _ =>
而不是 _ =>
?那 Nil
是做什么用的?
最佳答案
这是最近邮件列表上的一个主题:Help understanding RestHelper serve params .
基本上,它是一系列以中缀风格编写的unapply
方法。这意味着它相当于写它
case JsonGet(Nil, _) => Item.inventoryItems: JValue
和
case JsonPut(Nil, Item(item) -> _) => Item.add(item): JValue // or
case JsonPut(Nil, Tuple2(Item(item), _)) => Item.add(item): JValue
// using that -> denotes a Tuple
这让它看起来不那么巫术了。
关于scala - Scala/Lift 中 -> _ => 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8407132/