---
# System prepended metadata

title: Untitled

---

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


sealed trait Option[+A] {    
    
    def map[B](f: A => B): Option[B] = {
        fold(None, x => Some(f(x)))     
    }
    
    def flatMap[B](f: A => Option[B]): Option[B] =
        fold(None, f)f1
    
    def fold[B](default: => B, f: A => B): B = this match {
        case Some(v) => f(v)
        case None => default
    }
}
case class Some[A](value: A) extends Option[A]
case object None extends Option[Nothing]


Some(1) match {
    case Some(_) =>
    case None =>
}

Nothing <: Int/String/T
Int <: Any

Option[Nothing] <: Option[String]

val maybeMessage: Option[String] = ???

maybeMessage.fold(default = "No message", message => message.toUpper)
maybeMessage.fold(default = 0, message => message.size)
Some(10).fold(default = lastDigitOfPi(), _ + 1)

None.fold(0, _ + 1)      // 0
Some(10).fold(0, _ + 1)  // 11