Skip to content

Add IterableView.mapValues #203

Closed
@szeiger

Description

@szeiger

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions