Created
April 11, 2018 17:17
-
-
Save harmeetsingh0013/d579bbb50afa5c8477d17a8f24165d27 to your computer and use it in GitHub Desktop.
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
// 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