The following example from A Tour of Scala shows how implicit can be used to provide the corresponding missing elements (add and unit) based on type. The compiler will select the correct implicit scope object. The library also uses, for example, List.sortBy and Ordering or List.sum and Numeric .
However, the following use in class B is a valid / recommended use of implicit parameters (as opposed to using implicit in class A):
class I class A { def foo(i:I) { bar(i) } def bar(i:I) { baz(i) } def baz(i:I) { println("A baz " + i) } } (new A).foo(new I) class B { def foo(implicit i:I) { bar } def bar(implicit i:I) { baz } def baz(implicit i:I) { println("B baz " + i) } } (new B).foo(new I)
Where I primarily use implicit to save myself some typification on the call site when passing a parameter along the stack.
source share