How to change the following keys from the map without any variables full functional
HashMap(false -> List(20, 15, 20, 17), true -> List(50, 25, 45, 21, 100, 2000, 2100))
to
HashMap("String1" -> List(20, 15, 20, 17), "String2" -> List(50, 25, 45, 21, 100, 2000, 2100))
I tried with map and was able to change the keys to the same strings but not to different ones.
You can apply a map to all the items but focus only on the keys:
You can define
fto be a function or simply a constant map e.g.:Putting it all together:
Yields the expected result:
If you like one-liners you can also avoid a separate map / function:
Yet another way is to only treat the left side of the tuple:
And just for completeness, if your only elements really are
trueandfalseyou can just do: