|
|
|
|
|
by yawaramin
1392 days ago
|
|
You 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")
}
|
|