Created
          August 29, 2012 01:15 
        
      - 
      
- 
        Save tonymorris/3505850 to your computer and use it in GitHub Desktop. 
    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[+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