Implement a minimal `Option` that has `map` and `flatMap`. ```scala import scala.{Option => _} // implement here sealed trait Option[+T] { def isNone: Boolean def map[B](f: T => B): Option[B] = fold(None)(a => Some(f(a)) def flatMap[B](f: T => Option[B]): Option[B] = fold(None)(f) def fold[B](default: => B)(present: T => B): B = this match { case Some(value) => present(value) case None => default } } object None extends Option[Nothing] { def isNone: Boolean = true } case class Some[T](value: T) extends Option[T] { def isNone: Boolean = false } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up