Skip to content

Instantly share code, notes, and snippets.

@willf
Last active December 14, 2015 11:59
Show Gist options
  • Save willf/5083611 to your computer and use it in GitHub Desktop.
Save willf/5083611 to your computer and use it in GitHub Desktop.
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