Let's say I store bank accounts information in an immutable Map
:
val m = Map("Mark" -> 100, "Jonathan" -> 350, "Bob" -> 65)
and I want to withdraw, say, $50 from Mark's account. I can do it as follows:
val m2 = m + ("Mark" -> (m("Mark") - 50))
But this code seems ugly to me. Is there better way to write this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…