Last active
December 12, 2015 01:38
-
-
Save RaffaeleSgarro/4692738 to your computer and use it in GitHub Desktop.
This file contains 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
trait MyOption[A] { outer => | |
import MyOption._ | |
def fold[B](map: A => B, getOrElse: => B): B | |
} | |
object MyOption { | |
def none[A]: MyOption[A] = | |
new MyOption[A] { | |
def fold[B](map: A => B, getOrElse: => B): B = | |
getOrElse | |
} | |
def some[A](a: A): MyOption[A] = | |
new MyOption[A] { | |
def fold[B](map: A => B, getOrElse: => B): B = | |
map(a) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment