Reputation: 543
Does Scala have Double Side Queue similar to Java Deque or Python deque?
I see only Stack and Queue in Scala 2.12 API but just want to double check.
Upvotes: 6
Views: 2186
Reputation: 2144
Scala 2.13 has ArrayDeque
that internally uses a resizable circular buffer.
Reference:
https://www.scala-lang.org/api/current/scala/collection/mutable/ArrayDeque.html
Upvotes: 4
Reputation: 410
You can use Vector.drop or Vector.dropRight
val v = Vector(1,2,3)
v :+ 4 // Vector(1, 2, 3, 4)
0 +: v // Vector(0, 1, 2, 3)
v.drop(1) // Vector(2, 3)
v.dropRight(1) // Vector(1, 2)
Upvotes: 2