Additional two-chars-width __
placeholder would be useful for multiline continuous blocks with indentation of 2.
Current situation:
_.placeholder // awkward
.increaseWidth(2)
Proposal:
__.now
.itsFine(_.old(1).isStillAvailable)
Additional two-chars-width __
placeholder would be useful for multiline continuous blocks with indentation of 2.
_.placeholder // awkward
.increaseWidth(2)
__.now
.itsFine(_.old(1).isStillAvailable)
I don’t think I’ve ever needed this. Once the lambda becomes less than trivial I write a function with a named parameter.
It’s for those who are too lazy to invent new val/def names that looks nice in code and are meaningful…
sheet map { row =>
row.doSomething()
.doSomethingAgain()
// vs.
sheet map {
__.doSomething()
.doSomethingAgain()
}
I tend to never use a _
in a curly brace block. If I need to do that it’s also likely a sign that naming it would improve the code.
As much as the ragged indentation irks me at times, I believe this would have the potential to break quite a bit of Play code, as their JSON library defines __
as an alias:
The
play.api.libs.json
package defines an alias forJsPath
:__
(double underscore). You can use this if you prefer:val longPath = __ \ "location" \ "long"
Scala 3 for breaking changes
True, but it’s worth acknowledging what will break and weighing the cost to make sure it’s worth breaking.
I’m a bit dubious here, for a couple of reasons:
__
with, which complicates things.map(_.foo)
is way more common than the multi-lined chained version (though it does happen), so it appears to be adding a 1 character tax in the common case to help clean up formatting in an uncommon case. That seems a bit much.Would it be possible to solve this by making the formatter more sophisticated, so that it’ll recognize and indent accordingly?
Your sheet examples could look like this instead (I’d love it if we could get row
to indent cleanly as well):
sheet map { row =>
row.doSomething()
.doSomethingAgain()
// vs.
sheet map {
_.doSomething()
.doSomethingAgain()
}
I wouldn’t mind a token of arbitrarily many underscores replaced by underscore.
"hello" match {
case "hell" => "o, world"
case ______ => ______
}
Aligning underscores isn’t really pretty enough to catch on. Maybe a typographer out there could explain why.
"hello" match {
case "hell" => "o, world"
case __---> => ""
case __~~~> => ""
case __:::: => ""
}
The danger of double underscore is that val __:
is not val __ :
.
scala> (1 to 10) map (__ =>
| __.floatValue
| .floor
| )
I’m willing to try anything once.
scala> (1 to 10) map (__ =>
| __.floatValue
| .floor
| )