applyPairs(x,f) -- applies f to each pair (k,v) in the hash table x to produce a new hash table.
It produces a new hash table y from a hash table x by applying the function f to the pair (k,v) for each key k, where v is the value stored in x as x#k. Thus f should be a function of two variables which returns either a pair (kk,vv) which is placed into y, or it returns null, which signifies that no action be performed.
It is an error for the function f to return two pairs with the same key.
In this example, we show how to produce the hash table corresponding to the inverse of a function.
i1 : x = new HashTable from {1 => a, 2 => b, 3 => c} |
i2 : y = applyPairs(x, (k,v) -> (v,k)) |
i3 : x#2 |
i4 : y#b |
See also:
Ways to use applyPairs :