rsubseq returns a sequence of elements selected from a sorted collection, generating matches in reverse order—from the last matching element backward. It supports one bound or lower and upper bounds. section 9.1.3
Use the function with these contracts:
- Pass a sorted-set or sorted-map implementing clojure.lang.Sorted. section 9.1.3
- Use <, <=, >, or >= as the comparator; make each boundary key comparable with the collection contents. section 9.1.3
- Call (rsubseq sc test key) for one bound or (rsubseq sc start-test start-key end-test end-key) for two bounds. section 9.1.3
- Expect ClassCastException when the collection is not sorted or a boundary key is not comparable. section 9.1.3
Reverse range selection
(rsubseq (apply sorted-map (range 10)) <= 5) ;; ([4 5] [2 3] [0 1]) (rsubseq (apply sorted-set (range 10)) > 2 < 8) ;; (7 6 5 4 3)
Finding the greatest matching element
(defn greatest< [coll x] (first (rsubseq coll < x))) (def coll (sorted-map "a" 5 "f" 23 "z" 12 "g" 1 "b" 0)) (greatest< coll "f") ;; ["b" 0]
Listing 9.3. → Sequential selection, Searching, Range selection
(subseq ([sc test key]) ([sc start-test start-key end-test end-key])) (rsubseq ([sc test key]) ([sc start-test start-key end-test end-key]))
Browse the concise arity listing for subseq and rsubseq before applying their bound syntax. section 9.1.3
