---
# 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[S](f: T => S): Option[S]
    def flatMap[S](f: T => Option[S]): Option[S]
    def fold[S](op1: S)(f: T => S): S
} 

case class Some[+T](value: T) extends Option[T] {
    def map[S](f: T => S): Option[S] = Some(f(value))  
    def flatMap[S](f: T => Option[S]): Option[S] = f(value)
    def fold[S](op1: => S)(f: T => S): S = f(value)
}

case object None extends Option[Nothing] {
    def map[S](f: T => S): Option[S] = None
    def flatMap[S](f: T => Option[S]): Option[S] = None
    def fold[S](op1: S)(f: T => S): S = op1
}





val o1: Option[Int] = None
o1.map(i => s"Hello $i") //



val o1: Option[Int] = Some(1000)
o1.fold(calculateNFactorial(999999))(i => s"There is a value $i") // String



















```