Jay Taylor's notes
back to listing indeximplicits - Scala Identifier "implicitly" - Stack Overflow
[web search]
I have seen a function named
Note that we have to write | ||||
add comment | ||||
Here are a few reasons to use the delightfully simple method To understand/troubleshoot Implicit ViewsAn Implicit View can be triggered when the prefix of a selection (consider for example,
Implicit Views can also be triggered when an expression does not conform to the Expected Type, as below:
Here the compiler looks for this function:
Accessing an Implicit Parameter Introduced by a Context BoundImplicit parameters are arguably a more important feature of Scala than Implicit Views. They support the type class pattern. The standard library uses this in a few places -- see Scala 2.8 allows a shorthand syntax for implicit parameters, called Context Bounds. Briefly, a method with a type parameter
can be rewritten as:
But what's the point of passing the implicit parameter but not naming it? How can this be useful when implementing the method Often, the implicit parameter need not be referred to directly, it will be tunneled through as an implicit argument to another method that is called. If it is needed, you can still retain the terse method signature with the Context Bound, and call
Passing a subset of implicit parameters explicitlySuppose you are calling a method that pretty prints a person, using a type class based approach:
What if we want to change the way that the name is output? We can explicitly call
| |||||||||
|
It is commonly used to check if an implicit value of type Simple example from retronyms presentation )
| |||||||||||||||||||||
|
A "teach you to fish" answer is to use the alphabetic member index currently available in the Scaladoc nightlies. The letters (and the | |||||||||||||||||||||||||||
|