assoc-intersect ( assoc1 assoc2 -- intersection )
Factor handbook » The language » Collections » Associative mapping operations » Set-theoretic operations on assocs

Prev:assoc-subset? ( assoc1 assoc2 -- ? )
Next:assoc-union ( assoc1 assoc2 -- union )


Vocabulary
assocs

Inputs
assoc1an assoc
assoc2an assoc


Outputs
intersectiona new assoc


Word description
Outputs an assoc consisting of all entries from assoc2 such that the key is also present in assoc1.

Notes
The values of the keys in assoc1 are disregarded, so this word is usually used for set-theoretic calculations where the assoc in question either has dummy sentinels as values, or the values equal the keys.

Definition


: assoc-intersect ( assoc1 assoc2 -- intersection )
swap [ nip key? ] curry assoc-filter ;