Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

CLJS-242: copy over mapv & filterv from clojure.core

Pure copy & paste from Clojure (removing :added & :static metadata).
  • Loading branch information...
1 parent ce8e5d1 commit bf2c682398101bdc93d2f97cdad410cb214987f6 @michalmarczyk michalmarczyk committed with David Nolen
Showing with 25 additions and 0 deletions.
  1. +25 −0 src/cljs/cljs/core.cljs
25 src/cljs/cljs/core.cljs
@@ -2232,6 +2232,31 @@ reduces them without incurring seq initialization"
(persistent! (reduce -conj! (transient to) from))
(reduce -conj to from)))
+(defn mapv
+ "Returns a vector consisting of the result of applying f to the
+ set of first items of each coll, followed by applying f to the set
+ of second items in each coll, until any one of the colls is
+ exhausted. Any remaining items in other colls are ignored. Function
+ f should accept number-of-colls arguments."
+ ([f coll]
+ (-> (reduce (fn [v o] (conj! v (f o))) (transient []) coll)
+ persistent!))
+ ([f c1 c2]
+ (into [] (map f c1 c2)))
+ ([f c1 c2 c3]
+ (into [] (map f c1 c2 c3)))
+ ([f c1 c2 c3 & colls]
+ (into [] (apply map f c1 c2 c3 colls))))
+(defn filterv
+ "Returns a vector of the items in coll for which
+ (pred item) returns true. pred must be free of side-effects."
+ [pred coll]
+ (-> (reduce (fn [v o] (if (pred o) (conj! v o) v))
+ (transient [])
+ coll)
+ persistent!))
(defn partition
"Returns a lazy sequence of lists of n items each, at offsets step
apart. If step is not supplied, defaults to n, i.e. the partitions

0 comments on commit bf2c682

Please sign in to comment.
Something went wrong with that request. Please try again.