Maybe you want something like
def copy[T](dest: Seq[T], src: Seq[T]): Seq[T] = { require(dest.length >= src.length) src ++ (dest drop src.length) }
I am generalized to Seq s, but it works on List s, of course
The require method throws an IllegalArgumentException if not executed at run time
Then you only need to add the last ( yx ) elements of the destination list in the Source list (where x = src.length; y = dest.length)
You do this by discarding x elements from dest and adding the remaining to src .
This is what you get from REPL
scala> val src = List(1, 2, 3, 4) src: List[Int] = List(1, 2, 3, 4) scala> val dst = List(10, 20) dst: List[Int] = List(10, 20) scala> val dst2 = List(10, 20, 30, 40, 50, 60) dst2: List[Int] = List(10, 20, 30, 40, 50, 60) scala> copy(dst, src) java.lang.IllegalArgumentException: requirement failed at scala.Predef$.require(Predef.scala:221) at .copy(<console>:8) at .<init>(<console>:11) at .<clinit>(<console>) at .<init>(<console>:7) at .<clinit>(<console>) <...> scala> copy(dst2, src) res1: Seq[Int] = List(1, 2, 3, 4, 50, 60)