Created
January 18, 2012 02:46
-
-
Save gclaramunt/1630529 to your computer and use it in GitHub Desktop.
Simple list zipper
This file contains hidden or 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
case class ListZipper[T](rev:List[T], fwd:List[T]){ | |
override def toString = rev.reverse.toString ++" " ++ fwd.toString | |
def read:T= fwd.head | |
def add(c:T)=ListZipper(rev,c::fwd) | |
def update(c:T)=ListZipper(rev,c::fwd.tail) | |
def remove()=ListZipper(rev,fwd.tail) | |
def back=ListZipper(rev.tail,rev.head::fwd) | |
def forward=ListZipper(fwd.head::rev,fwd.tail) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment