Skip to content

Instantly share code, notes, and snippets.

@lazyval
Forked from excavador/OAuth2Test.sc
Last active December 15, 2015 19:39
Show Gist options
  • Save lazyval/5313079 to your computer and use it in GitHub Desktop.
Save lazyval/5313079 to your computer and use it in GitHub Desktop.
// it's good style to mark such objects/classes with sealed to guide complier
// so it will check if match is exhaustive (all possible cases covered)
sealed abstract class Response
sealed abstract class Reason
abstract class TokenType
case class Token(t: TokenType) extends Response
case class Problem(reason: Reason) extends Response
case object InvalidResponse extends Reason
case object Connection extends Reason
// note that order of this classes in mattern matching matters
class OneTime extends TokenType
class Refreshable extends OneTime {
def refresh() = ???
}
/*
foo match {
case Token(t: Refreshable) => do something with t
case Problem(reason) => reason match {
case InvalidResponse => ...
case ConnectionFailure => ...
}
_ => // just an example: Token(OneTime) will go there
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment