Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Option[A] {
- def flatMap[B](f: A => Option[B]): Option[B]
- def map[B](f: A => B): Option[B]
- }
- case class None[A]() extends Option[A] {
- def flatMap[B](f: A => Option[B]): Option[B] = None[B]
- def map[B](f: A => B): Option[B] = None[B]
- }
- // return the give parameter wrapped in option
- def unit[T](aType: T): Option[T] = Some(aType)
- case class Some[A](a: A) extends Option[A] {
- def flatMap[B](f: A => Option[B]): Option[B] = f(a)
- def map[B](f: A => B): Option[B] = unit(f(a))
- }
Add Comment
Please, Sign In to add comment