docs.scala-lang icon indicating copy to clipboard operation
docs.scala-lang copied to clipboard

Updated example for filtering keys from Map

Open mukesh210 opened this issue 3 years ago • 3 comments

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".

mukesh210 avatar Nov 12 '21 03:11 mukesh210

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 avatar Nov 12 '21 03:11 SethTisue

@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.

mukesh210 avatar Nov 12 '21 03:11 mukesh210

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.)

SethTisue avatar Mar 11 '22 18:03 SethTisue