If you do not mind creating an additional object, there are
def fill[CC[_]](n: Int) = new { def apply[A](elem: => A)(implicit cbf: CanBuildFrom[Nothing, A, CC[A]]) = { val b = cbf() 1 to n foreach { _ => b += elem } b.result } }
This does not bypass the objection (2), but the use is pleasant:
scala> fill[List](3)("wish") res0: List[java.lang.String] = List(wish, wish, wish) scala> fill[Array](3)("wish") res1: Array[java.lang.String] = Array(wish, wish, wish)
source share