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

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

Description

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

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

o1 : HashTable
i2 : applyPairs(H, (k,v) -> (k+1, v+10))

o2 = HashTable{2 => 20}
               3 => 25
               4 => 30

o2 : HashTable
i3 : applyPairs(H, (k,v) -> (v,k))

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

o3 : HashTable

If H is not a hash table, then apply(pairs H, f) is called.

i4 : applyPairs({4, 5, 6}, (i, x) -> i * x)

o4 = {0, 5, 12}

o4 : List

Caveat

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

See also

Ways to use applyPairs:

  • applyPairs(BasicList,Function)
  • applyPairs(Dictionary,Function)
  • applyPairs(HashTable,Function)
  • applyPairs(Thing,Function)

For the programmer

The object applyPairs is a compiled function.


The source of this document is in Macaulay2Doc/functions/applyPairs-doc.m2:43:0.