Implicit Parameters

In Providing Default Values for Parameters you learned about default values for parameters—if you don’t pass an argument for a parameter, Scala will give it a default value. That’s nice; we don’t have to give values that are intuitively obvious or that can be inferred by default. But the default value that’s given is decided by the creator of the function and not the caller. Scala provides an alternative, so the caller can decide what value to send—by default—instead of the function definer deciding that.

Let’s consider an example that will benefit from this feature. With smartphones and mobile devices that we all carry around, we constantly have to connect to different networks: one network at home, another at the office, ...

Get Pragmatic Scala 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.