Macaulay2 » Documentation
Packages » Macaulay2Doc > The Macaulay2 language > hash tables > applyKeys
next | previous | forward | backward | up | index | toc

applyKeys -- apply a function to each key in a hash table

Synopsis

Description

i1 : H = new HashTable from {1 => 10, 2 => 15, 3 => 20}

o1 = HashTable{1 => 10}
               2 => 15
               3 => 20

o1 : HashTable
i2 : applyKeys(H, k -> k + 100)

o2 = HashTable{101 => 10}
               102 => 15
               103 => 20

o2 : HashTable
i3 : applyKeys(H, k -> k//2, max)

o3 = HashTable{0 => 10}
               1 => 20

o3 : HashTable
i4 : applyKeys(H, k -> k//2, plus)

o4 = HashTable{0 => 10}
               1 => 35

o4 : HashTable

Caveat

It is an error for the function f to return two pairs with the same key. When this is a possibility, use the function g to specify how the two pairs should be reconciled.

See also

Ways to use applyKeys :

For the programmer

The object applyKeys is a compiled function.