gpt4 book ai didi

scala - Scala/Lift 中 -> _ => 是什么意思?

转载 作者:行者123 更新时间:2023-12-03 04:15:59 24 4
gpt4 key购买 nike

在“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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com