---
# System prepended metadata

title: Untitled

---

Write a data structure that represents the effect of the possibility of a value A, like Option in Scala
It needs to support construction of instances, `map` and `flatMap` 

```scala
import scala.{Option => _}


trait Maybe[A] { 

    def map[B](f: A => B): Maybe[B] = {
        this.fold(f andThen(Some(_)), None)
    }
    
    def flatMap[B](f: A => Maybe[B]): Maybe[B] = {
        this.fold(f, None)
    }
    
    def fold[B](f: A => B, isEmpty: B): B = {
        this match {
            case Some(a) => f(a)
            case None => isEmpty
        }
    }
    
}

case object None extends Maybe[Nothing]
case class Some[A](a: A) extends Maybe[A]


val a = Some(5)

a.map { v =>
    v + v
}

val a = Some(5)
val b = Some(3)

a.flatMap { v =>
    Some(v + 3) 
}



```