---
# System prepended metadata

title: Untitled

---

Implement a minimal `Option` that has `map` and `flatMap`.
```scala
import scala.{Option => _}

sealed trait Option[+T] {
    def map[A](func: T => A): Option[A] =
        fold[Option[T]](None)(value => func andThen Some)
    
    def flatMap[A](func: T => Option[A]): Option[A] =
        fold[Option[T]](None)(func)
    
    def fold[A](zero: => A)(func: T => A): A = this match {
        case Some(value) =>
            func(value)
        case None =>
            zero
    }
}
case class Some(value: T) extends Option[T]
case object None extends Option[Nothing]

val someOption: Option[Int] = Some(5)
val noneOption: Option[Int] = None


Some(5).fold(2)(_ + 1) // 6
None.fold(2)(_ + 1) // 2

def primeCalculator(n: Int): Int = ???

Some(5).fold(primeCalculator(Int.MaxValue))(_ + 1) 