docs.scala-lang
docs.scala-lang copied to clipboard
Updated example for filtering keys from Map
This is regarding below example: "val twoAndThree = m.view.filterKeys(Set(2,3)).toMap"
filterKeys
is not a member of scala.collection.IterableView
, so the example mentioned gives compile time error. Therefore, I updated the example to not use "view" and "toMap".
I think you must be using Scala 2.11 or 2.12?
The Scala collections changed a lot between 2.12 and 2.13.
The example works as written in both Scala 2.13 and Scala 3.
https://docs.scala-lang.org/overviews/scala-book/collections-maps.html aims to cover 2.13. At least, I don't think it's necessarily intended to work in 2.12 too? @alvinj?
@SethTisue Thanks for the info... I updated Scala version in local to 2.13 and it's working fine. Can we somehow mention that "example would work with 2.13 or later" in documentation.
I believe a pull request adding that to https://docs.scala-lang.org/overviews/scala-book/introduction.html and/or https://docs.scala-lang.org/overviews/scala-book/prelude-taste-of-scala.html would be accepted. (I don't think we want to scatter such disclaimers throughout the book.)