collections - In Scala, apply function to values for some keys in immutable map -


let immutable map

val m = (0 3).map {x => (x,x*10) }.tomap m: scala.collection.immutable.map[int,int] = map(0 -> 0, 1 -> 10, 2 -> 20, 3 -> 30) 

a collection of keys of interest

val k = set(0,2) 

and function

def f(i:int) = + 1 

how apply f onto values in map mapped keys of interest resulting map be

map(0 -> 1, 1 -> 10, 2 -> 21, 3 -> 30) 

m.transform{ (key, value) => if (k(key)) f(value) else value } 

Comments

Popular posts from this blog

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -