Skip to content

Add IterableView.mapValues #203

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
szeiger opened this issue May 13, 2019 · 3 comments · Fixed by #220
Closed

Add IterableView.mapValues #203

szeiger opened this issue May 13, 2019 · 3 comments · Fixed by #220

Comments

@szeiger
Copy link
Contributor

szeiger commented May 13, 2019

2.12:

scala> res0.mapValues(x=>  x^2)
res7: scala.collection.immutable.Map[String,Int] = Map(32 -> 1)

2.13:

scala> res0.mapValues(x=>  x^2).toMap
            ^
       warning: method mapValues in trait MapOps is deprecated (since 2.13.0): Use .view.mapValues(f). A future version will include a strict version of this method (for now, .view.mapValues(f).toMap).
res9: scala.collection.immutable.Map[String,Int] = Map(32 -> 1)

The recommended replacement does not compile in 2.12:

scala> Map(1 -> 2).view.mapValues(x => x*x)
<console>:12: error: value mapValues is not a member of scala.collection.IterableView[(Int, Int),scala.collection.immutable.Map[Int,Int]]
       Map(1 -> 2).view.mapValues(x => x*x)
                        ^

This could be remedied by adding an extension method for map-like IterableViews.

@SethTisue
Copy link
Member

SethTisue commented Jun 15, 2019

for anyone here on this ticket wondering about a workaround in the meantime, consider whether your code would still work if you replaced .mapValues(f) with .map{case (k, v) => (k, f(v)). and if you do need the laziness, perhaps you can .iterator your way to laziness

szeiger added a commit to szeiger/scala-collection-compat that referenced this issue Jun 17, 2019
@japgolly
Copy link

Came here to report this, awesome that it's already been fixed! Any idea when the next release is coming?

@SethTisue
Copy link
Member

@lrytz another possible rewrite

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

Successfully merging a pull request may close this issue.

3 participants