---
# System prepended metadata

title: Untitled

---


Implement a minimal `Option` that has `map` and `flatMap`.


```scala
import scala.{Option => _}
// implement here


sealed trait Option[+T] {

    def map[P](fn: T => P): Option[P] = {
        fold(x => Some(fn(x)), None)
        // this match {
        //     case Some(value) => Some(fn(value))
        //     case None => None
        // }
    }
    
    def flatMap[P](fn: T => Option[P]): Option[P] = {
        fold(fn, None)
        // this match {
        //     case Some(value) => fn(value)
        //     case None => None
        // }
    }
    
    def fold[P](someFn: T => P, noneFn: => P): P = {
        this match {
            case Some(value) => someFn(value)
            case None => noneFn
        }
    }
    
}

case object None extends Option[Nothing]
case class Some[T](value: T) extends Option[T]




























```