Why no immutable arrays in scala standard library?

前端 未结 7 1538
死守一世寂寞
死守一世寂寞 2020-12-23 21:27

Scala has all sorts sorts of immutable sequences like List, Vector,etc. I have been surprised to find no implementation of immutable indexed sequence backed by a simple arra

7条回答
  •  独厮守ぢ
    2020-12-23 22:11

    You could cast your array into a sequence.

    val s: Seq[Int] = Array(1,2,3,4)
    

    The array will be implicitly converted to a WrappedArray. And as the type is Seq, update operations will no longer be available.

提交回复
热议问题