I would have thought the following code:
val a = Array(1, 2, 3, 4, 5)
println(a.map(n => "x"))
Could be abbreviated to:
val a = Array(1, 2, 3, 4, 5)
println(a.map("x"))
But the latter gives me the exception below. Why is this?
java.lang.StringIndexOutOfBoundsException: String index out of range: 1 java.lang.StringIndexOutOfBoundsException: String index out of range: 1 at java.lang.String.charAt(String.java:658) at scala.collection.immutable.StringLike$class.apply(StringLike.scala:52) at scala.collection.immutable.WrappedString.apply(WrappedString.scala:33) at scala.collection.immutable.WrappedString.apply(WrappedString.scala:33) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245) at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245) at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33) at scala.collection.mutable.ArrayOps$ofInt.foreach(ArrayOps.scala:234) at scala.collection.TraversableLike$class.map(TraversableLike.scala:245) at scala.collection.mutable.ArrayOps$ofInt.map(ArrayOps.scala:234)