2011-12-06 54 views
10

在 「簡單地提起」 休息例子中,我們可以找到Scala/Lift中的 - > _ =>是什麼意思?

case Nil JsonGet _ => Item.inventoryItems: JValue 

case Nil JsonPut Item(item) -> _ => Item.add(item): JValue 

的爲什麼-> _ =>代替_ =>?那是什麼Nil

回答

13

這是郵件列表上的話題最近: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 

這使得它看起來少了幾分巫術。