Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does -> _ => mean in Scala/Lift?

Tags:

scala

lift

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?

like image 225
Ivan Avatar asked Dec 06 '11 21:12

Ivan


People also ask

What is the meaning of => in Scala?

=> 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 .

What does LIFT mean in functional programming?

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.

What is a partial function in Scala?

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.


1 Answers

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.

like image 173
Debilski Avatar answered Sep 18 '22 16:09

Debilski