How to find the definition of methods / operations defined in an implicitly transformed class?

I look at the other source (Scala), where I can see that the operator :+= is called to a variable of type IndexedSeq . I look at all scaladocs page for this class to find out what makes this statement, but I do not see it. I think that either it is defined in the class outside the IndexedSeq inheritance IndexedSeq , or the javascript on the scaladocs page hides it somewhere, I do not see it. (This is not really the case; see the answer below.)

I hit every button on the scaladocs page, trying to display everything. I looked at the HTML code of the webpage. There must be a way to find the operator of the class documentation to which it can be applied. Did not have?

(NB: I was looking for a statement using symbolhound , so I know what that statement means. This question is about scala documentation in general, and not that particular statement.)

+7
scala
source share
2 answers

All statements in Scala are common methods.

You cannot find it because it is a compiler mask for re-binding, it is not an operator. Or to say it another way: it looks like a private operator, but in fact it is "operator followed by the symbol = ".

The compiler will magically transform it into an assignment, if the operator (here :+ ) returns the correct type, and the initial value was var , obviously.

Since it is not provided by any implicit or explicit method on Seq[T] or anything else, it does not appear anywhere in the generated skalyadok.

So, to answer the general question:

  • It is a language construct, so the only place where it is documented, - a specification, unfortunately,
  • but if you can find somewhere unknown operator "<?>=" , find the definition of "<?>" , which necessarily documented.

Change Finally, I found where this is defined in SLS:

ยง6.12.4:

The assignment operator is a symbol of the operator (op syntax category in (ยง1.1)), which ends with the equal sign "=", with the exception of operators for which one of the following conditions is true:

(1) an operator also begins with an equal sign or

(2) the operator is one of (<=), (> =), (! =).

Further, he also says that this happens only when all other options (including the potential implications) were tested.

+9
source share

Is this value assigned to a variable? If this is the case, I think the sugar syntax:

 scala> var x = IndexedSeq(1,2,3) x: IndexedSeq[Int] = Vector(1, 2, 3) scala> x :+= 10 scala> x res59: IndexedSeq[Int] = Vector(1, 2, 3, 10) scala> val y = IndexedSeq(1,2,3) y: IndexedSeq[Int] = Vector(1, 2, 3) scala> y :+= 10 <console>:16: error: value :+= is not a member of IndexedSeq[Int] y :+= 10 ^ ) scala> var x = IndexedSeq(1,2,3) x: IndexedSeq[Int] = Vector(1, 2, 3) scala> x :+= 10 scala> x res59: IndexedSeq[Int] = Vector(1, 2, 3, 10) scala> val y = IndexedSeq(1,2,3) y: IndexedSeq[Int] = Vector(1, 2, 3) scala> y :+= 10 <console>:16: error: value :+= is not a member of IndexedSeq[Int] y :+= 10 ^ ) scala> var x = IndexedSeq(1,2,3) x: IndexedSeq[Int] = Vector(1, 2, 3) scala> x :+= 10 scala> x res59: IndexedSeq[Int] = Vector(1, 2, 3, 10) scala> val y = IndexedSeq(1,2,3) y: IndexedSeq[Int] = Vector(1, 2, 3) scala> y :+= 10 <console>:16: error: value :+= is not a member of IndexedSeq[Int] y :+= 10 ^ 

This syntactic sugar for the "operation and use", such as += :

 scala> var x = 10 x: Int = 10 scala> x += 1 scala> x res63: Int = 11 

What are de-sugars for x = x + 1 .

+1
source share

All Articles