---
# 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[N](f: T => N): Option[N] = {
        fold(None)(Some(f(_)))
    }
    
    def flatMap[N](f: T => Option[N]): Option[N] = {
        fold(None)(f)
    }
    
    def fold[N](ifEmpty: N)(f: T => N): N = {
       this match {
           case None    => ifEmpty
           case Some(e) => f(e)
       }
    }
}

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

def f(i: Int): Option[String] = ???

val r = Some(12).flatMap(i: Int => f(i))  


```