Created
July 23, 2016 13:57
-
-
Save JoolsF/5378268689474c15b3f3a46c656d62b0 to your computer and use it in GitHub Desktop.
Boolean extractor
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
/** | |
* 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