assoc-find ( ... assoc quot: ( ... key value -- ... ? ) -- ... key value ? )
Factor handbook » The language » Collections » Associative mapping operations » Associative mapping combinators

Prev:assoc-each ( ... assoc quot: ( ... key value -- ... ) -- ... )
Next:assoc-map ( ... assoc quot: ( ... key value -- ... newkey newvalue ) -- ... newassoc )


Vocabulary
assocs

Inputs
assocan assoc
quota quotation with stack effect ( ... key value -- ... ? )


Outputs
keythe successful key, or f
valuethe successful value, or f
?a boolean


Word description
Applies a predicate quotation to each entry in the assoc. Returns the key and value that the quotation succeeds on, or f for both if the quotation fails. It also returns a boolean describing whether there was anything found; this can be used to distinguish between a key and a value equal to f, or nothing being found.

Definition


: assoc-find
( ... assoc quot: ( ... key value -- ... ? ) -- ... key value ? )
assoc-operator find swap
[ first2-unsafe t ] [ drop f f f ] if ; inline