I have class Seq and I want to have method "multy" that adds number to List factors, but I want, that only Seq of Number types will have this method, for this example, val numbers should work with multy, and val strings shouldn't.
import scala.collection.mutable.ListBuffer object Main extends App{ val strings = new Seq("f", "d", "a") val numbers = new Seq(1,5,4,2) val strings2 = new Seq("c", "b") numbers.multy(5) strings.multy(5) val strings3 = strings2.concat(strings) println(strings3) println(numbers) } class Seq[T : Ordering] (initialElems: T*) { override def toString: String = elems.toString val factors = ListBuffer[Number](1) val elems = initialElems.sorted def concat(a:Seq[T]) = new Seq(a.elems ++ this.elems:_*) def multy[T <: Number](a:Number) = { factors += a; } }
multydo for types that are not supported?scala.Int,scala.Double, etc are not subclasses ofNumber