Skip to content

Instantly share code, notes, and snippets.

@RaffaeleSgarro
Last active December 12, 2015 01:38
Show Gist options
  • Save RaffaeleSgarro/4692738 to your computer and use it in GitHub Desktop.
Save RaffaeleSgarro/4692738 to your computer and use it in GitHub Desktop.
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