What does double underscore in Scala import mean?

Suppose you import a library as follows:

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

What does double underscore do?

+6
source share
2 answers

JsPath is the main 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 child JsPath instance using syntax similar to a JsValue traversal:

 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 want:

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

+8
source

this is importing a value from a json package object:

 package object json { /** * Alias for `JsPath` companion object */ val __ = JsPath } 
+4
source

Source: https://habr.com/ru/post/979170/


All Articles