---
# 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] = this match {
        case Some(v) => Some(f(v))
        case None    => None
    }
    
    def flatMap[B](f: A => Option[B]): Option[B] = this match {
        case Some(v) => f(v)
        case None    => None
    }
    
    def fold[B](d: => B)(f: A => B): B = this match {
        case Some(v) => f(v)
        case None    => d
    }
    
    def mapViaFold[B](f: A => B): Option[B] = {
      fold(None)(x => Some(f(x)))
    }
    
    def flatMapViaFold[B](f: A => Option[B]): Option[B] =
      fold(None)(f)
}

case class Some[T](v: T) extends Option[T]

case object None extends Option[Nothing]

Some(1).fold(10000thprime)(_ + 1)

None.mapViaFold(_ + 1) == None