scala - Why does immutable.ParMap.mapValues return ParMap instead of immutable.ParMap? -
in scala 2.11.6 application have defined immutable.parmap so:
object foos { val foos: immutable.parmap[string, foo] = immutable.parmap( ... ) } later on, i'd create new immutable.parmap using same keys, use mapvalues:
val fooservices: immutable.parmap[string, fooservice] = exchanges.exchanges mapvalues (_.fooservice) scala complains
expression of type parmap[string, fooservice] not conform expected type parmap[string, fooservice].
as workaround can use comprehension, compiler permits:
val fooservices: immutable.parmap[string, fooservice] = ((name, ex) <- foos.foos) yield name -> foo.fooservice but nice able use library functions designed exact task. why can't mapvalues infer specific type here?
it's not matter of inferring specific type. it's instance of scala.collection.parallel.parmaplike$$anon$2, view of underlying map (the created map forwards operations original).
it have been created separately immutable , mutable branches, have better code-sharing in library, created once, in parmaplike. return type correct in type of immutable .mapvalues same of mutable .mapvalues.
if don't want view (implemented proxy) regenerate collection, use map instead. i.e. xs.mapvalues(v => f(v)) becomes xs.map{ case (k,v) => (k, f(v)) } , new immutable parmap generated , typed such.
Comments
Post a Comment