When I tried to println MapView
I have been got a message MapView(<not computed>)
val phonebook = Map("Jim" -> 555, "Daniel" -> 789)
println(phonebook) // Map(Jim -> 555, Daniel -> 789)
val filteredMap = phonebook.filterKeys(_.startsWith("J"))
println(filteredMap("Jim")) // 555
println(filteredMap) // MapView(<not computed>)
If I defined filteredMap
as following
val filteredMap = phonebook.view.filterKeys(_.startsWith("J"))
then nothing have been changed. Scala version is 2.13.2
Why mapview cannot be printed and what is the best way to fix it?
Add .toMap
to convert your mapView into a static map. As suggested by @ Luis Miguel Mejía Suárez
val filteredMap = phonebook.view.filterKeys(_.startsWith("J")).toMap
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With