Finding something that satisfies in a collection is a common operation, and many collection/container types provides such interface.
- Returns an element that satisfies the predicate. If the collection is a mapping, returns key and value as two values.
- Takes a predicate and a collection.
- Some take a failure thunk as the third argument. If the operation doesn't take a failure thunk,
#f is returned when no satisfying entry is found.
Note: If it doesn't take failure thunk, it can't handle the case when
as an element satisfies the predicate.
- A predicate receives an element, if the collection is a simple collection of values; or it receives a key and an associated value, if the collection is a mapping.
- Predicate receives key and value: hashmap-find?, mapping-find?.
- hash-table-find?(SRFI-125) - Returns what predicate returns, rather than the actual key & value. With this regard, it belongs to
- hashtable-find?(SRFI-126) - Arguments are reversed (a collection, a predicate). Returns three values ([key, value, found?])
- imaping-find?(SRFI-224? draft) - predicate takes only a value.
- If the collection is ordered, there can be a variant to find the last
entry that satisfies the predicate.
- Returns the first true value returned by the predicate.
- Argument variations:
- pred, collection -> result or
- pred, collection, collection2 ... -> result or
- pred, collection, optional failure thunk:
- pred, collection, optional start and end:
- Unresolved question: If mapping collection wants the multiple-collection interface, how should the arguments passed to the predicate?
any but act as a predicate---either return
- Standard ones: bag-any??(SRFI-113),
- imapping-any?? - predicate takes only a value.
- In bit-set operations, the predicate is obvious so it only
takes a collection, plus start/end arguments:
- Wrap the return value with Maybe, eliminating the failure thunk and
allowing multiple values packed into a single one.
- Predicate gets a key and a value: imapping-query/key?(SRFI-224? draft)
- Predicate gets a value: imapping-query?(SRFI-224? draft)
- The predicate returns Maybe. If it's Just, it is returned immediately.
- So far, we don't have an instance for this .