Skip to content

immutable.Map.filterKeys should return immutable.Map #751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scabug opened this issue Apr 15, 2008 · 7 comments
Closed

immutable.Map.filterKeys should return immutable.Map #751

scabug opened this issue Apr 15, 2008 · 7 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Apr 15, 2008

collection.immutable.Map.filterKeys should return collection.immutable.Map

Now it returns collection.Map.Projection. So

var map = Map[Int, Int] = ...
map = map.filterKeys(...)

is not possible.

(Map is Predef.Map == immutable.Map)

@scabug
Copy link
Author

scabug commented Apr 15, 2008

Imported From: https://issues.scala-lang.org/browse/SI-751?orig=1
Reporter: @stepancheg

@scabug
Copy link
Author

scabug commented Apr 16, 2008

@mcdirmid said:
I have no idea why I put filterKeys in, as it is redundant with with filter. The submitter should use filter and just look at the key vs. filterKeys. I need to check why filterKeys is there, and if there is no good reason, deprecate it for eventual removal.

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone next_bugfix deleted

@scabug
Copy link
Author

scabug commented May 19, 2009

@paulp said:
In r17770 I changed filterKeys to just use filter, so in line with the rest of the new collections it returns the same type of collection. I also suggested it be deprecated, but either way it may as well do the right thing.

@scabug
Copy link
Author

scabug commented May 19, 2009

@odersky said:
I think it's better to leave it as a view for the moment. If you want the same kind of map, use filter. Once (if?) we have systematic views for maps we can deprecate it.

@scabug
Copy link
Author

scabug commented Mar 12, 2010

@dcsobral said:
Seems to work now:

scala> var map = Map(1 -> "a", 2 -> "b", 3 -> "c")
map: scala.collection.immutable.Map[Int,java.lang.String] = Map((1,a), (2,b), (3,c))

scala> map = map.filterKeys(_ % 2 == 0)
map: scala.collection.immutable.Map[Int,java.lang.String] = Map(2 -> b)

Built from: 2.8.0.r0-b20100306211516

@scabug
Copy link
Author

scabug commented Mar 14, 2010

@paulp said:
(In r21162) Test case closes #751. No review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants