Add standard arities to into.
This commit is contained in:
parent
50587dd35e
commit
c50e46e970
1 changed files with 35 additions and 25 deletions
|
|
@ -73,32 +73,42 @@
|
||||||
([f init]
|
([f init]
|
||||||
(reduce (fn ([] init) ([acc] (f acc)) ([acc x] (f acc x))))))
|
(reduce (fn ([] init) ([acc] (f acc)) ([acc x] (f acc x))))))
|
||||||
|
|
||||||
|
(defn- into-rf [to]
|
||||||
|
(cond
|
||||||
|
(instance? clojure.lang.IEditableCollection to)
|
||||||
|
(if (map? to)
|
||||||
|
(kvrf
|
||||||
|
([] (transient to))
|
||||||
|
([acc] (persistent! acc))
|
||||||
|
([acc x] (conj! acc x))
|
||||||
|
([acc k v] (assoc! acc k v)))
|
||||||
|
(fn
|
||||||
|
([] (transient to))
|
||||||
|
([acc] (persistent! acc))
|
||||||
|
([acc x] (conj! acc x))))
|
||||||
|
(map? to)
|
||||||
|
(kvrf
|
||||||
|
([] to)
|
||||||
|
([acc] acc)
|
||||||
|
([acc x] (conj acc x))
|
||||||
|
([acc k v] (assoc acc k v)))
|
||||||
|
:else
|
||||||
|
(fn
|
||||||
|
([] to)
|
||||||
|
([acc] acc)
|
||||||
|
([acc x] (conj acc x)))))
|
||||||
|
|
||||||
(defn into
|
(defn into
|
||||||
"Returns a transducer which accumulate every input in a collection and outputs only the accumulated collection."
|
"Like clojure.core/into but with a 1-arg arity returning a transducer which accumulate every input in a collection and outputs only the accumulated collection."
|
||||||
[coll]
|
([to]
|
||||||
(reduce (cond
|
(reduce (into-rf to)))
|
||||||
(instance? clojure.lang.IEditableCollection coll)
|
([to from]
|
||||||
(if (map? coll)
|
(into to identity from))
|
||||||
(kvrf
|
([to xform from]
|
||||||
([] (transient coll))
|
(let [rf (xform (into-rf to))]
|
||||||
([acc] (persistent! acc))
|
(if-let [rf (and (map? from) (satisfies? clojure.core.protocols/IKVReduce from) (some-kvrf rf))]
|
||||||
([acc x] (conj! acc x))
|
(rf (clj/reduce-kv rf (rf) from))
|
||||||
([acc k v] (assoc! acc k v)))
|
(rf (clj/reduce rf (rf) from))))))
|
||||||
(fn
|
|
||||||
([] (transient coll))
|
|
||||||
([acc] (persistent! acc))
|
|
||||||
([acc x] (conj! acc x))))
|
|
||||||
(map? coll)
|
|
||||||
(kvrf
|
|
||||||
([] coll)
|
|
||||||
([acc] acc)
|
|
||||||
([acc x] (conj acc x))
|
|
||||||
([acc k v] (assoc acc k v)))
|
|
||||||
:else
|
|
||||||
(fn
|
|
||||||
([] coll)
|
|
||||||
([acc] acc)
|
|
||||||
([acc x] (conj acc x))))))
|
|
||||||
|
|
||||||
(defmacro ^:private or-instance? [class x y]
|
(defmacro ^:private or-instance? [class x y]
|
||||||
(let [xsym (gensym 'x_)]
|
(let [xsym (gensym 'x_)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue