Skip to content

Instantly share code, notes, and snippets.

@JoolsF
Created July 23, 2016 13:57
Show Gist options
  • Save JoolsF/5378268689474c15b3f3a46c656d62b0 to your computer and use it in GitHub Desktop.
Save JoolsF/5378268689474c15b3f3a46c656d62b0 to your computer and use it in GitHub Desktop.
Boolean extractor
/**
* A Boolean extractor
* Unapply method doesn't have to reside in companion object of the class for which it is applicable
*/
object premiumCandidate{
def unapply(user: FreeUser): Boolean = user.upgradeProbability > 0.75
}
def initiateSpamProgram(freeUser: FreeUser) = () //do something useful here
user match {
case freeUser @ premiumCandidate() => initiateSpamProgram(freeUser)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment