Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is List[String~Int]?

While going through the scala documentation (Play Docs) of the play framework I saw a syntax I have never seen before.

val populations:List[String~Int] = {
  SQL("select * from Country").as( str("name") ~ int("population") * ) 
}

Could someone please tell me what does "~" in List[String~Int] mean?

like image 427
rahul Avatar asked Apr 13 '12 07:04

rahul


People also ask

What is list in C# example?

List in C# is a collection of strongly typed objects. These objects can be easily accessed using their respective index. Index calling gives the flexibility to sort, search, and modify lists if required. In simple, List in C# is the generic version of the ArrayList.

Is a list a pointer?

List<T> is an object, so yes, it is "like a pointer" (I use that term loosely since objects in managed code are not called "pointers", they're called references). List and String are identical in this regard.

What does list t mean?

List<T> class represents the list of objects which can be accessed by index. It comes under the System. Collection. Generic namespace. List class can be used to create a collection of different types like integers, strings etc.

How do I return a string from a list in C#?

In C# you can simply return List<string> , but you may want to return IEnumerable<string> instead as it allows for lazy evaluation.


1 Answers

May be this willl help:

scala> class ~[A, B]
defined class $tilde

scala> List.empty[String~Int]
res1: List[~[String,Int]] = List()

Actually, ~ is not a part of the standard library, this is a generic class from the play framework, which allows an infix notation. In scala, any generic class that takes 2 generic parameters can be use with an infix notation. for example, the following also works:

scala> class X[A, B]
defined class X

scala> List.empty[String X Int]
res1: List[X[String,Int]] = List()

In your case, you will find the definition of ~ in the Play framework API.

like image 70
Nicolas Avatar answered Oct 17 '22 12:10

Nicolas