Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » hash tables » mapping over hash tables » scanPairs
next | previous | forward | backward | up | index | toc

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

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

If t is not a hash table, then scan(pairs t, f) is called.

i4 : scanPairs({4, 5, 6}, print)
(0, 4)
(1, 5)
(2, 6)

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:

  • scanPairs(HashTable,Function)
  • scanPairs(Thing,Function)

For the programmer

The object scanPairs is a compiled function.


The source of this document is in Macaulay2Doc/ov_hashtables.m2:615:0.