Skip to content

Instantly share code, notes, and snippets.

@dcsobral
Forked from tonymorris/ListZipper.scala
Created August 30, 2012 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcsobral/3544613 to your computer and use it in GitHub Desktop.
Save dcsobral/3544613 to your computer and use it in GitHub Desktop.
List Zipper
case class ListZipper[+A](lefts: List[A], x: A, rights: List[A]) {
def map[B](f: A => B): ListZipper[B] =
sys.error("todo")
// map with zipper context
def coFlatMap[B](f: ListZipper[A] => B): ListZipper[B] =
sys.error("todo")
def findRight(p: A => Boolean): Option[ListZipper[A]] =
sys.error("todo")
def findLeft(p: A => Boolean): Option[ListZipper[A]] =
sys.error("todo")
def :=[AA >: A](a: AA): ListZipper[AA] =
ListZipper(lefts, a, rights)
def toList: List[A] =
lefts.reverse ::: x :: rights
}
object ListZipper {
def fromList[A](a: List[A]): Option[ListZipper[A]] =
a match {
case Nil => None
case h::t => Some(ListZipper(Nil, h, t))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment