- 
      
- 
        Save casualjim/5497870 to your computer and use it in GitHub Desktop. 
    simple exercise around map and flatmap
  
        
  
    
      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
    
  
  
    
  | object GOption { | |
| def some[A](a: A): GOption[A] = new GOption[A] { | |
| def cata[B](n: => B, s: A => B): B = sys.error("Implement me") | |
| } | |
| def none[A]: GOption[A] = new GOption[A] { | |
| def cata[B](n: => B, s: A => B): B = sys.error("Implement me") | |
| } | |
| } | |
| trait GOption[+A] { | |
| import GOption._ | |
| def cata[B](none: => B, some: A => B): B | |
| def map[B](f: A => B): GOption[B] = sys.error("Implement me in terms of cata") | |
| def flatMap[B](f: A => GOption[B]): GOption[B] = sys.error("Implement me in terms of cata") | |
| def getOrElse[B >: A](b: => B): B = sys.error("Implement me in terms of cata") | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment