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

selectPairs -- select a part of a hash table by pairs

Description

i1 : x = hashTable{(1, 2), (2, 4), (3, 6), (4, 8), (5, 10)}

o1 = HashTable{1 => 2 }
               2 => 4
               3 => 6
               4 => 8
               5 => 10

o1 : HashTable
i2 : selectPairs(x, (k,v) -> odd(k + v))

o2 = HashTable{1 => 2 }
               3 => 6
               5 => 10

o2 : HashTable
i3 : selectPairs(2, x, (k, v) -> odd(k + v))

o3 = HashTable{1 => 2}
               3 => 6

o3 : HashTable

If x is not a hash table, then select(pairs x, f) (or select(n, pairs x, f)) is called.

i4 : selectPairs(toList(1..10), (i, x) -> even x)

o4 = {(1, 2), (3, 4), (5, 6), (7, 8), (9, 10)}

o4 : List
i5 : selectPairs(3, toList(1..10), (i, x) -> even x)

o5 = {(1, 2), (3, 4), (5, 6)}

o5 : List

Caveat

If x is a hash table, then it must be immutable.

See also

Ways to use selectPairs:

  • selectPairs(BasicList,Function)
  • selectPairs(HashTable,Function)
  • selectPairs(ZZ,BasicList,Function)
  • selectPairs(ZZ,HashTable,Function)

For the programmer

The object selectPairs is a compiled function.


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