Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add cljs.core/rsubseq

Copy & paste from Clojure's core.clj, with minor adjustments.
  • Loading branch information...
commit d9a529f68796a35ae33d7fc69db3799a47d03116 1 parent 205193d
@michalmarczyk michalmarczyk authored David Nolen committed
Showing with 15 additions and 0 deletions.
  1. +15 −0 src/cljs/cljs/core.cljs
View
15 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]
Object
(toString [this]
Please sign in to comment.
Something went wrong with that request. Please try again.