It is possible to provider some default given contextual for class method?

58 Views Asked by At

Suppose I have defined a class Test:

import scala.collection.{IterableFactory, Factory}

class Test:
    def p1[C[_]](xs: Int*)(using f: Factory[Int, C[Int]]): C[Int] = f.fromSpecific(xs)
    def p2[C[_]](xs: Int*)(using f: IterableFactory[C]): C[Int] = f(xs*)

Then I can write following codes since there are implicit methods implicit def iterableFactory[A]: Factory[A, CC[A]] = IterableFactory.toFactory(this) defined in List, Seq, etc.:

 val t = new Test
 t.p1[List](1, 2, 3)

However, I can not write t.p2[List](1, 2, 3) directly. Instead I must define given IterableFactory[List] first, or using t.p2(1, 2, 3)(using List).

My question: Is there any solution such that t.p2(1, 2, 3) works automatically? Such as define some given instances in object Test or so?

0

There are 0 best solutions below