Browse files

Add cljs.core/rsubseq

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 d9a529f68796a35ae33d7fc69db3799a47d03116
Showing with 15 additions and 0 deletions.
  1. +15 −0 src/cljs/cljs/core.cljs
@@ -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]
(toString [this]

0 comments on commit d9a529f

Please sign in to comment.