Skip to content

Instantly share code, notes, and snippets.

@PavelZaytsev
Last active November 29, 2018 06:16
Show Gist options
  • Save PavelZaytsev/9234deec2aa647c1fc6ed6eca381bb3f to your computer and use it in GitHub Desktop.
Save PavelZaytsev/9234deec2aa647c1fc6ed6eca381bb3f to your computer and use it in GitHub Desktop.
sealed trait Option[+A]
case class Some[+A](get: A) extends Option[A]
case object None extends Option[Nothing]
sealed trait EitherError[Exception, +A]
case class RecoverableError(e: Exception)
extends EitherError[Exception, Nothing]
case class Result[+A](value: A) extends EitherError[Exception, A]
object Option {
def map[A, B](o: Option[A])(f: A => B): Option[B] = o match {
case Some(value) => Some(f(value))
case None => None
}
}
object EitherError {
def map[A, B](e: EitherError[Exception, A])(
f: A => B): EitherError[Exception, B] = e match {
case Result(value) => Result(f(value))
case re @ RecoverableError(_) => re
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment