score:0

Accepted answer

The only thing I can think of is quite ugly (but might be acceptable):

implicit class Scan1lDable[T, Repr](v: DistTraversableLike[T, Repr]) {
  def scan1lD[That](op: (T,T) => T) // Note: no T1
                   (implicit bf: CanBuildFrom[Repr, T, That]): That = {
    // snip
  }
}

Now, your example will work, but the following will not:

class A
class B extends A

def op(x: A, y: B) = x

val x: DistTraversableLike[B, ...] = ...
x.scan1lD(op _)

But this will:

(x: DistTraversableLike[A, ...]).scan1lD(op _)

So we add a convenience method to DistTraversableLike

trait DistTraversableLike[+T, +Repr]
  extends DistTraversable[T] {
  self: Repr =>

  def lower[S >: T]: DistTraversableLike[S, Repr] = this

}

And can now call:

x.lower[A].scan1lD(op _)

Granted, it is really ugly, but might be more acceptable than having to specify the method types.


Related Query

More Query from same tag