Skip to content

Instantly share code, notes, and snippets.

@lforite
Created October 22, 2021 07:48
Show Gist options
  • Save lforite/b86daea837983277bac0886243fa6fda to your computer and use it in GitHub Desktop.
Save lforite/b86daea837983277bac0886243fa6fda to your computer and use it in GitHub Desktop.
Scala web series Pt. 1 authorization predicate combinators
trait AuthorizationPredicate { self =>
def evaluate(token: Token): Boolean
def &&(predicate: AuthorizationPredicate): AuthorizationPredicate = new AuthorizationPredicate {
override def evaluate(token: Token): Boolean = self.evaluate(token) && predicate.evaluate(token)
}
def ||(predicate: AuthorizationPredicate): AuthorizationPredicate = new AuthorizationPredicate {
override def evaluate(token: token): Boolean = self.evaluate(token) || predicate.evaluate(token)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment