Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the symbol "That" mean in Scala

Tags:

generics

scala

I've seen several examples of code using the symbol "That" with Generics. i.e.

def map[B, That](f : (A) => B) : That

But, due to the lack of google-ability of that word, I can't find any documentation on what it does or how I use it.

Is it simply a normal type placeholder, or does it do something special?

like image 279
James Davies Avatar asked Feb 13 '13 07:02

James Davies


People also ask

What are Scala symbols?

Defined in Symbols, a Symbol is a unique identifier for a definition (e.g. a method, type, or field). A ClassSymbol extends Symbol and represents either a class , or a trait , or an object . A Symbol can even refer to non-Scala entities, such as from the Java standard library.

What is symbol literal in Scala?

Symbol literals A symbol literal 'x is a shorthand for the expression scala. Symbol("x") . Symbol is a case class, which is defined as follows. package scala final case class Symbol private (name: String) { override def toString: String = "'" + name }

What is manifest in Scala?

A Manifest[T] is an opaque descriptor for type T. Its supported use is to give access to the erasure of the type as a Class instance, as is necessary for the creation of native Arrays if the class is not known at compile time.

What is reflection in Scala?

Scala reflection enables a form of metaprogramming which makes it possible for programs to modify themselves at compile time. This compile-time reflection is realized in the form of macros, which provide the ability to execute methods that manipulate abstract syntax trees at compile-time.


1 Answers

Any identifiers inside [...] are treated as type parameters.

So in case of def map[B, That](f : (A) => B) : That That only means a generic return type. Replace it with Z for example: def map[B, Z](f : (A) => B) : Z would have the exact same effect.

like image 113
pedrofurla Avatar answered Nov 15 '22 11:11

pedrofurla