What it is not so good for

Even though the by-name parameter method looks nice and could make our writing shorter, it might not be a great idea here. A big disadvantage compared with our previous example is that we could actually plug any Unit data there, which could possibly not be relevant to what the receivers are supposed to do. In other cases, though, the by-name parameter technique is quite useful and could dramatically improve our application performance.

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.