Macaulay2 » Documentation
Packages » Macaulay2Doc :: scanPairs
next | previous | forward | backward | up | index | toc

scanPairs -- apply a function to the pairs in a hash table

Synopsis

Description

scanPairs(t, f) applies the function f to each pair (k, t#k) in the hash table t. In other words, f is applied to each key k paired with its corresponding value t#k.

i1 : t = hashTable {{1,8},{2,20},{3,4},{4,20}}

o1 = HashTable{1 => 8 }
               2 => 20
               3 => 4
               4 => 20

o1 : HashTable
i2 : scanPairs(t, (k,v) -> print (k+v))
9
22
7
24
i3 : scanPairs(t, (k,v) -> if v==20 then print k)
2
4

Caveat

This function requires an immutable hash table. To scan the pairs in a mutable hash table, use scan(pairs t, f).

See also

Ways to use scanPairs :

For the programmer

The object scanPairs is a compiled function.