---
# System prepended metadata

title: Untitled

---

Implement a minimal `Option` that has `map` and `flatMap`.
```scala
import scala.{Option => _}


sealed trait Option[+A] {
    def map[B](a: A => B) : Option[B] = this match {
        case None => None
        case Some(v) => Some(a(v))
    }
    
    def flatMap[B](a: A => Option[B]) : Option[B] = this match {
        case None => None
        case Some(v) => a(v)
    }
    
    def fold[B](d: => B)(f: A => B) : B = this match {
        case None => d
        case Some(v) => f(v)
    }
}

case class Some[+A](v: A) extends Option[A]
case object None          extends Option[Nothing]




for{
    o1 <- Some(1)
    o2 <- Some(3)
} yield o1 + o2

sealed trait Animal
case object Cat


val z: Option[Animal] = None: Option[???]



Option[Animal] :> Option[???]

val x = None().map(s => s.length)
val y = None.flatMap(s => Some(s.length))
