6 ms·
That is a curried parameter in {}. Those braces are not for scoping. They basically define a lambda. You can probably use () instead you can also use import la
by AzzieElbab 4y ago
That is a curried parameter in {}. Those braces are not for scoping. They basically define a lambda. You can probably use () instead
you can also use import language.experimental.fewerBraces with nightly builds to write code like this
List(1,2,3).map:
c => ...
- yawaramin 4y agoThe braces here absolutely denote a new scope. You can't bind vals inside parentheses, for example. You can inside braces. > You can probably use () instead I would rather not as using braces for the final argument has been the Scala idiom for a long time now.
- AzzieElbab 4y agoI see your point. However you don’t have to define that thunk inline. You can write it separately and just pass it by name retry(…)(thunk). Not sure what signature of the retry method looks like.
- yawaramin 4y agoYou can define it separately but it's often not the idiom. Especially for call-by-name arguments like in this case: def retry[A](backoffSeconds: Seq[Int])(action: => A): A In this case you can't just define a 'val action = ...' because you don't want it to be run immediately, you want to run it inside the 'retry' method only. You could define it as a 'def' but then you're just introducing two different delayed evaluation concepts into this small piece of code. The cleanest way is to just directly pass in the action and Scala ensures it is delayed evaluation thanks to the CBN parameter type: retry(Seq(1, 2, 3)) { println("Trying") }