Reputation: 2481
I am finding myself writing alot of boilerplate scala to add implicit class wrappers around modules of functions. For example, if I have this function defined for Seqs
def takeWhileRight[T](p: T=>Boolean)(s: Seq[T]): Seq[T] = s.reverse.takeWhile(p).reverse
I need to write this (completely deterministic) implicit wrapper:
implicit class EnrichSeq[T](value: Seq[T]) {
def takeWhileRight(p: T=>Boolean): Seq[T] = SeqOps.takeWhileRight(p)(value)
}
This is one example of many. In every case the implicit wrapper ends up being mechanically derivable from the function it forwards to.
Is anyone aware of any tools or code generators that can automate the generation of such wrappers?
Upvotes: 0
Views: 178
Reputation: 26486
You're using Scala 2.10's "implicit classes" already? The whole point (the only point) of that new syntactic sugar is to free you from having to write the implicit conversion method.
Upvotes: 1