Skip to content

Instantly share code, notes, and snippets.

@paulp
Created February 19, 2014 03:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulp/9085746 to your computer and use it in GitHub Desktop.
Save paulp/9085746 to your computer and use it in GitHub Desktop.
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