next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc > The Macaulay2 language > hash tables > applyPairs

applyPairs -- apply a function to each pair in a hash table

Synopsis

Description

The result of applyPairs(H,f) is a new hash table obtained by applying the function f to each key/value pair (k,v) in H and storing the resulting key/value pair in the new hash table. If the function returns null then no action is performed.

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}

o1 = HashTable{1 => a}
               2 => b
               3 => c

o1 : HashTable
i2 : y = applyPairs(x, (k,v) -> (v,k))

o2 = HashTable{a => 1}
               b => 2
               c => 3

o2 : HashTable
i3 : x#2

o3 = b

o3 : Symbol
i4 : y#b

o4 = 2

Caveat

It is an error for the function f to return two pairs with the same key.

See also

Ways to use applyPairs :