---
# 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] = {
        this match {
            case None => None
            case Some(a) = Some(f(a))
        }
    }
    
    def flatMap[B](f: A => Option[B]): Option[B] = {
        this match {
            case None => None
            case Some(a) => f(a)
        }
    }
    
    def fold[B](f: A => B, g: => B): B = {
        this match {
            case None => g
            case Some(a) => f(a)
        }
    }
    
 
    
}

o.fold(
    f => f + 1,
    0
)

List(1, 2, 3, 4).map(Int => Int) : List[Int]

List(1, 2, 3, 4).flatMap(A => List[B])

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

case object None extends Option[Nothing];


val n: ??? = None

foo(n)

def foo(animal: Option[Animal])


enum Option<A> {
    None,
    Some(A)
}







```