Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import scala.collection.mutable.ListBuffer
class Ummutable[T] private (buf: ListBuffer[T]) {
def this(xs: T*) = this(ListBuffer() ++= xs)
def append(ys: T*): this.type = { buf ++= ys ; this }
val xs: List[T] = buf.toIterable match { case xs: List[T] => xs }
override def toString = s"Ummutable(xs = ${xs mkString ", "})"
}
object Ummm {
def main(args: Array[String]): Unit = {
val um = new Ummutable(1, 2, 3)
println("um: " + um.xs)
um append (4, 5, 6)
println("um: " + um.xs)
}
// um: List(1, 2, 3)
// um: List(1, 2, 3, 4, 5, 6)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.