Skip to content

Instantly share code, notes, and snippets.

@gclaramunt
Created January 18, 2012 02:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gclaramunt/1630529 to your computer and use it in GitHub Desktop.
Save gclaramunt/1630529 to your computer and use it in GitHub Desktop.
Simple list zipper
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