Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class GenericTest extends App{
- defaultParamFunc(2,3){(x:Int, y:Int) => x*y }
- trait MyMagnet[B] extends ((B,B) => B)
- object MyMagnet {
- implicit def fromFunc[B]( f: (B, B) => B ) = new MyMagnet[B] {
- def apply(z: B, y: B): B = {
- val ans = f(z,y)
- println("ans : " + ans)
- ans
- }
- }
- implicit def fromUnit[B](unit: Unit)(implicit num: Numeric[B]) = new MyMagnet[B]{
- import num._
- def apply(v1: B, v2: B): B = { v1 + v2 }
- }
- }
- def defaultParamFunc[B](z: B, y: B)(magnet: MyMagnet[B]): B = magnet(z, y)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement