Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the double underscore in Scala imports mean?

Say you're importing a library like so:

import play.api.libs.json.{__, Writes }

What does the double underscore do?

like image 717
reectrix Avatar asked Dec 05 '14 12:12

reectrix


1 Answers

JsPath is a core building block for creating Reads/Writes. JsPath represents the location of data in a JsValue structure. You can use the JsPath object (root path) to define a JsPath child instance by using syntax similar to traversing JsValue:

import play.api.libs.json._

val json = { ... }

// Simple path
val latPath = JsPath \ "location" \ "lat"

// Recursive path
val namesPath = JsPath \\ "name"

// Indexed path
val firstResidentPath = (JsPath \ "residents")(0)

The play.api.libs.json package defines an alias for JsPath: __ (double underscore). You can use this if you prefer:

val longPath = __ \ "location" \ "long"

like image 158
Naha Avatar answered Sep 20 '22 04:09

Naha