---
# 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) { a =>
            Some(f(a))
        }
        // this match {
        //     case Some(a) => Some(f(a))
        //     case None => None
        // }
    }
    
    def flatMap[B](f: A => Option[B]): Option[B] = {
        this.fold[Option[B]](None)(f)
        // this match {
            // case Some(a) => f(a)
            // case None => None
        // }
    }
    
    def fold[B](z: => B)(f: A => B): B = {
        this match {
            case Some(a) =>f(a)
            case None => z
        }
    }
    
    Some(1).fold(launchRocket)(identity)
}

case class Some[A](a: A) extends Option[A]

case object None extends Option[Nothing]










```