---
# System prepended metadata

title: Untitled

---

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

Function[-I, +T]

sealed trait Option[+E] {
    def isDefined: Boolean    
    def isEmpty = !isDefined
    
    def map[E1](f : E => E1): Option[E1] = {
        fold(None)(element: E => Some(f(element))) //Function0
    }
    
    
    def flatMap[E1](f : E => Option[E1]): Option[E1] = {
        fold(None)(element: E => f(element))
    }
    
    def fold[E1](fnEmpty: => E1)(fn: E => E1): E1 = {
        this match {
            case None => fnEmpty
            case Some(element) => fn(element)
        }
    }
}

case object None extends Option[Nothing] {
    def isDefined = false
    
    def map[E1](f : Nothing => E1): Option[E1] = None
    def flatMap[E1](f : Nothing => Option[E1]): Option[E1] = None
}

case class Some[+E](element: E) extends Option[E] {
    def isDefined = true
    
    def map[E1](f : E => E1): Option[E1] = Some(f(element))
    def flatMap[E1](f : E => Option[E1]): Option[E1] = f(element)
}

```