(This article is an excerpt from the Scala Cookbook.)
Here’s a simple Scala call-by-name example. I’ll show the normal approach to writing a method and passing in a parameter, and then show a call-by-name (pass by name) example.
1) A “normal” Scala method (call-by-value)
Here I show how to pass a parameter to a method “normally,” i.e., call by value: