Skip to content

Commit

Permalink
Add cljs.core/rsubseq
Browse files Browse the repository at this point in the history
Copy & paste from Clojure's core.clj, with minor adjustments.
  • Loading branch information
michalmarczyk authored and David Nolen committed May 2, 2012
1 parent 205193d commit d9a529f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/cljs/cljs/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5295,6 +5295,21 @@ reduces them without incurring seq initialization"
(take-while (mk-bound-fn sc end-test end-key)
(if ((mk-bound-fn sc start-test start-key) e) s (next s))))))

(defn rsubseq
"sc must be a sorted collection, test(s) one of <, <=, > or
>=. Returns a reverse seq of those entries with keys ek for
which (test (.. sc comparator (compare ek key)) 0) is true"
([sc test key]
(let [include (mk-bound-fn sc test key)]
(if (#{< <=} test)
(when-let [[e :as s] (-sorted-seq-from sc key false)]
(if (include e) s (next s)))
(take-while include (-sorted-seq sc false)))))
([sc start-test start-key end-test end-key]
(when-let [[e :as s] (-sorted-seq-from sc end-key false)]
(take-while (mk-bound-fn sc start-test start-key)
(if ((mk-bound-fn sc end-test end-key) e) s (next s))))))

(deftype Range [meta start end step ^:mutable __hash]
Object
(toString [this]
Expand Down

0 comments on commit d9a529f

Please sign in to comment.