What does the _2 mean in the following code? Where can I find the official documentation for this?
..
@if(errors) {
<p class="error">
@errors.head._2
</p>
}
...
What does the _2 mean in the following code? Where can I find the official documentation for this?
..
@if(errors) {
<p class="error">
@errors.head._2
</p>
}
...
The ._2 selects the second element in a tuple e.g.
val t = (1,2)
t._2
so @errors in your sample appears to be a list of tuples. You can find the documentation here for Tuple2, and there are Tuple3, Tuple4 etc. classes for tuples of size 3, 4 etc. The scala package documentation shows the available Tuple types which go up to size 22.
In this instance, I believe _2 is just a field name, representing the 2nd field of a Tuple2 object.
The underscore is sometimes a bit more magical, however. It's used as a wildcard in import statements, as a non-assigning placeholder in assignments that need a value for syntax but shouldn't actually do any, and as a variable that should be there but whose value doesn't matter in pattern matching.
It's for pattern matching, you can find documentation about it here
edit: I believe its main purpose is to match anything, for example if you do "import http._" it will import everything from that library.