Last active
November 29, 2018 06:16
-
-
Save PavelZaytsev/9234deec2aa647c1fc6ed6eca381bb3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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