How to return Array[B] rather than ArraySeq[B]

As I said in another thread, the reason for this is that arrays aren’t classes with type parameters, but a low-level datatype of the JVM.

This means, that type erasure does not apply to the parameter of an array (an Array[Int] and an Array[Double] are different types at runtime). But this in turn also means, that to create an array, you need the information about that type at runtime. You want to create an Array[B], but B is a type parameter that is erased at runtime.

To keep the required information, you’d have to change the type parameters to def map[A, B: ClassTag] (ClassTag from scala.reflect). So you will have to change the signature in your trait.