This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,20 @@
class HVar[A](initialValue: A) extends Proxy {
override def self = !this
override def toString = "HVar(" + !this + ")"
def history = _history
private var _history = List(initialValue)
def unary_! = _history.head
def :=(newValue: A): Unit = {
_history = newValue :: _history
}
def modify(f: A => A): Unit = {
_history = f(!this) :: _history
}
def undo: A = {
val v = !this
_history = _history.tail
v
}
}

View file

@ -0,0 +1,21 @@
scala> val h = new HVar(3)
h: HVar[Int] = HVar(3)
scala> h := 11
scala> h := 90
scala> !h
res32: Int = 90
scala> h.history
res33: List[Int] = List(90, 11, 3)
scala> h.undo
res34: Int = 90
scala> h.undo
res35: Int = 11
scala> h.undo
res36: Int = 3