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?
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.
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.
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.
In C# you can simply return List<string> , but you may want to return IEnumerable<string> instead as it allows for lazy evaluation.
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.
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