Last active
December 14, 2015 11:59
-
-
Save willf/5083611 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
object SalaryWorld extends App { | |
val rules = Seq( | |
('allowance, 1.2), | |
('bonus, 1.1), | |
('tax, 0.7), | |
('surcharge, 0.9) | |
) | |
def salary(config: Set[Symbol], base: Double) = | |
rules.foldLeft(base)((prior, rule) => if (config.contains(rule._1)) prior * rule._2 else prior) | |
def run = { | |
println(salary(Set('surcharge, 'tax, 'bonus, 'allowance), 100000)) | |
println(salary(Set('allowance, 'tax), 100000)) | |
} | |
run | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment