Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "outer =>" really mean?

Tags:

scala

Is there any documentation on the "outer =>" feature? It looks like a self type annotation with an infered type. However I have the feeling that I am wrong.

If it would be the case, is it only a different way to express access to super?

trait A extends (B => C) {
  outer =>
  def apply(x: B): C = outer(x)
}
like image 624
Joa Ebert Avatar asked Dec 04 '10 14:12

Joa Ebert


People also ask

What do you mean by outer?

adjective. situated on or toward the outside; external; exterior: outer garments; an outer wall. situated farther out or farther from the center: the outer reaches of space.

What does the outer limits mean?

The outermost parts or boundary of an area or object. perimeter. boundary. border. confines.

What does outskirts Mean Mean?

out·​skirt ˈau̇t-ˌskərt. : a part remote from the center : border. usually used in plural. on the outskirts of town.

What does outer state mean?

​coming from or happening in a different state.


2 Answers

Not super, but the outer scope. It's a way to aliasing different scopes. For example:

class A(val x:Int) { thisA =>
 class B { 
   val x = 2 
   val y = x + thisA.x // without thisA how could we use A.x instead of B.x ? (*)
 }
}

There is a better illustration here.

(*) There exist another way to have the same effect, but it's beyond this question.

like image 132
pedrofurla Avatar answered Oct 23 '22 07:10

pedrofurla


It is a different way to access this. It is useful in cases where an outer this would be shadowed by another this in an inner class. That way, you can just give the outer this an additional (the original this would still be available when it is in scope so it’s not a renaming) name.

like image 6
Debilski Avatar answered Oct 23 '22 06:10

Debilski