Then f can implicitly apply as long as its parameter is implicitly available,
f.implicitApply should be("OK")
,
Given a function f that requires an call-by-name Ordering[Int]
def f0(x: => Ordering[Int]) = "OK"val f = f0 _
Then f can implicitly apply as long as its parameter is implicitly available,
f.implicitApply should be("OK")
Note
You can optionally add an implicit modifier on the function parameter.
val f = { implicit x: Ordering[Int] =>"OK"
}
f.implicitApply should be("OK")
It is very useful when you create a curried function.
def g[A] = { (i: A, j: A) =>implicit x: Ordering[A] =>import x._
if (i > j) {
s"$i is greater than $j"
} else {
s"$i is not greater than $j"
}
}
g(1, 2).implicitApply should be("1 is not greater than 2")
This member is added by an implicit conversion from ImplicitApply[F] to
any2stringadd[ImplicitApply[F]] performed by method any2stringadd in scala.Predef.
This member is added by an implicit conversion from ImplicitApply[F] to
StringFormat[ImplicitApply[F]] performed by method StringFormat in scala.Predef.
A dependent type class that apply
F
with implicit values as parameters.Imports
import com.thoughtworks.feature.ImplicitApply.ops._
This will enable the implicitApply method for any functions
Author:
杨博 (Yang Bo) <[email protected]>
The function type to be implicitly apply
Given a function
f
that requires anOrdering[Int]
Then
f
can implicitly apply as long as its parameter is implicitly available,f.implicitApply should be("OK")
Given a function
f
that requires an call-by-nameOrdering[Int]
Then
f
can implicitly apply as long as its parameter is implicitly available,f.implicitApply should be("OK")
You can optionally add an implicit modifier on the function parameter.
It is very useful when you create a curried function.