Skip to content

Instantly share code, notes, and snippets.

@vdebergue
Forked from atamborrino/simpleMonadicDataType.scala
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save vdebergue/5f9d3ac165ef96d759c4 to your computer and use it in GitHub Desktop.

Select an option

Save vdebergue/5f9d3ac165ef96d759c4 to your computer and use it in GitHub Desktop.
sealed trait IOToolResponse[+A] {
def flatMap[B](f: A => IOToolResponse[B]): IOToolResponse[B]
def map[B](f: A => B): IOToolResponse[B] = this.flatMap(a => IOToolResponse.unit(f(a)))
}
object IOToolResponse {
def unit[A](a: A): IOToolResponse[A] = Authenticated(a)
}
case class Authenticated[A](data: A) extends IOToolResponse[A] {
def flatMap[B](f: A => IOToolResponse[B]) = f(data)
}
case class NotAuthenticated(code: String, msg: String) extends IOToolResponse[Nothing] {
def flatMap[B](f: A => IOToolResponse[B]) = this
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment