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