Skip to content

Instantly share code, notes, and snippets.

View andrelaszlo's full-sized avatar
🤓

André Laszlo andrelaszlo

🤓
View GitHub Profile
@andrelaszlo
andrelaszlo / PitTree.scala
Created October 28, 2009 22:41 — forked from AlexanderWingard/PitTree.scala
Added the new pretty toString method
class PitTree[T](val children : Map[String, PitTree[T]], val value : Option[T]) extends Map[String, T] {
def this() = this(Map(), None)
def this(value : T) = this(Map(), Some(value))
def update(path : String, upVal : T) : PitTree[T] = update(splitPath(path), upVal)
def update(path : List[String], upVal : T) : PitTree[T] = path match {
case Nil =>
new PitTree[T](upVal)
case h :: t =>
val child = children.getOrElse(h, new PitTree[T]()).update(t, upVal)
new PitTree[T](children + (h -> child), value)