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?
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.
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 }
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.
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.
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.
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