I have the following map Map(FULL -> 3854.0, REMAINING -> 3769.0)
I would like to compute the two values such that the (FULL/REMAINING)*100
Is there an good way to do this? I tried m.foldLeft(0)(_/_._2) but the compilier is complaining about a type mismatch between float and Int?
I have the following map Map(FULL -> 3854.0, REMAINING -> 3769.0) I would like
Share
You can fix the type mismatch by specifying
0.0as the first argument tofoldLeft, but that won’t make your code right. It will then compute0.0/3854.0/3769.0which equals0.0.In fact,
Map(FULL -> 3854.0, REMAINING -> 3769.0)is not guaranteed to be ordered, so I’m pretty sure the best you can do ism('FULL') / m('REMAINING').Perhaps you want to create a
case classfor this instead, in which case you could just saym.full/m.remainingor even make a method to compute that automatically.