lundi 20 avril 2015

using impilicits to make apply method easier to use

I have the following setup:

trait Pr[I0<:ArgLike,I1<:ArgLike,+O]
  extends ((I0, I1) => O) {
  val name: String
  def apply(arg0,arg1):O
}

case class sum(arg0:Arg1,arg1: Arg2) extends Pr[Arg1,Arg2,t1]{
    val name = "adder"
    def apply(a0:Arg1,a1:Arg2) = t1(a0.toString + a1.toString + "output")
}

When I want to use sum I have to pass the arguments two times (one for case class, one for apply).

val b0 = Arg1("a0")
val b1 = Arg2()
val s = sum(b0,b1)(b0,b1)

How can I use implicits to make this easier and more intuitive, something like this:

val s = sum(b0,b1)

I want to have access to arg0 and arg1, something like sum.arg0 so I want them to be member of Predicate.

Aucun commentaire:

Enregistrer un commentaire