Created
February 19, 2014 03:50
-
-
Save paulp/9085746 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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