Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@harmeetsingh0013
Created April 11, 2018 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harmeetsingh0013/d579bbb50afa5c8477d17a8f24165d27 to your computer and use it in GitHub Desktop.
Save harmeetsingh0013/d579bbb50afa5c8477d17a8f24165d27 to your computer and use it in GitHub Desktop.
// add any two integer value
def addInt(a: Int, b: Int): Int = a + b
// add employe salary to their account balances
def addMoneyMap(balances: Map[String, Money], salary: Map[String, Money]): Map[String, Money] = {
balances.foldLeft(salaries){
case (acc, (name, money)) =>
acc + (name -> acc.get(name).map(addMoney(_ , money)).getOrElse(money))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment