Indexing
Functions retrieving or sorting based on list indices and related predicates.
Function: -elem-index (elem list)
Return the first index of elem in list. That is, the index within list of the first element that is equal to elem. Return nil if there is no such element.
See also: -find-index (see -find-index).
(-elem-index 2 '(6 7 8 3 4))
⇒ nil(-elem-index "bar" '("foo" "bar" "baz"))
⇒ 1(-elem-index '(1 2) '((3) (5 6) (1 2) nil))
⇒ 2Function: -elem-indices (elem list)
Return the list of indices at which elem appears in list. That is, the indices of all elements of list equal to elem, in the same ascending order as they appear in list.
(-elem-indices 2 '(6 7 8 3 4 1))
⇒ ()(-elem-indices "bar" '("foo" "bar" "baz"))
⇒ (1)(-elem-indices '(1 2) '((3) (1 2) (5 6) (1 2) nil))
⇒ (1 3)Function: -find-index (pred list)
Return the index of the first item satisfying pred in list. Return nil if no such item is found.
pred is called with one argument, the current list element, until it returns non-nil, at which point the search terminates.
This function’s anaphoric counterpart is --find-index.
See also: -first (see -first), -find-last-index (see -find-last-index).
(-find-index #'numberp '(a b c))
⇒ nil(-find-index #'natnump '(1 0 -1))
⇒ 0(--find-index (> it 5) '(2 4 1 6 3 3 5 8))
⇒ 3Function: -find-last-index (pred list)
Return the index of the last item satisfying pred in list. Return nil if no such item is found.
Predicate pred is called with one argument each time, namely the current list element.
This function’s anaphoric counterpart is --find-last-index.
See also: -last (see -last), -find-index (see -find-index).
(-find-last-index #'numberp '(a b c))
⇒ nil(--find-last-index (> it 5) '(2 7 1 6 3 8 5 2))
⇒ 5(-find-last-index (-partial #'string< 'a) '(c b a))
⇒ 1Function: -find-indices (pred list)
Return the list of indices in list satisfying pred.
Each element of list in turn is passed to pred. If the result is non-nil, the index of that element in list is included in the result. The returned indices are in ascending order, i.e., in the same order as they appear in list.
This function’s anaphoric counterpart is --find-indices.
See also: -find-index (see -find-index), -elem-indices (see -elem-indices).
(-find-indices #'numberp '(a b c))
⇒ ()(-find-indices #'numberp '(8 1 d 2 b c a 3))
⇒ (0 1 3 7)(--find-indices (> it 5) '(2 4 1 6 3 3 5 8))
⇒ (3 7)Function: -grade-up (comparator list)
Grade elements of list using comparator relation. This yields a permutation vector such that applying this permutation to list sorts it in ascending order.
(-grade-up #'< '(3 1 4 2 1 3 3))
⇒ (1 4 3 0 5 6 2)(let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-up #'< l) l))
⇒ (1 1 2 3 3 3 4)Function: -grade-down (comparator list)
Grade elements of list using comparator relation. This yields a permutation vector such that applying this permutation to list sorts it in descending order.
(-grade-down #'< '(3 1 4 2 1 3 3))
⇒ (2 0 5 6 3 1 4)(let ((l '(3 1 4 2 1 3 3))) (-select-by-indices (-grade-down #'< l) l))
⇒ (4 3 3 3 2 1 1)