In "Simply Lift" REST examples we can find
case Nil JsonGet _ => Item.inventoryItems: JValue
but
case Nil JsonPut Item(item) -> _ => Item.add(item): JValue
Why -> _ =>
instead of _ =>
? And what's that Nil
for?
=> is syntactic sugar for creating instances of functions. Recall that every function in scala is an instance of a class. For example, the type Int => String , is equivalent to the type Function1[Int,String] i.e. a function that takes an argument of type Int and returns a String .
Lambda lifting is a meta-process that restructures a computer program so that functions are defined independently of each other in a global scope. An individual "lift" transforms a local function into a global function.
A partial function is a function that does not provide an answer for every possible input value it can be given. It provides an answer only for a subset of possible data, and defines the data it can handle. In Scala, a partial function can also be queried to determine if it can handle a particular value.
This was a topic on the mailing list recently: Help understanding RestHelper serve params.
Basically, it is a series on unapply
methods written in infix style. This means it is equivalent to writing it
case JsonGet(Nil, _) => Item.inventoryItems: JValue
and
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
which makes it appear a bit less voodoo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With