(loop [n 10 res []] (if (zero? n) res (recur (dec n) (conj res n))))
[10 9 8 7 6 5 4 3 2 1]
(reduce (fn [acc el] (if (> (rand) 0.5) (reduced acc) (conj acc el))) [] (range))
[0 1 2 3]
(update-in {:a [1 2 3]} [:a] (fn [x] (conj (pop x) (inc (peek x)))))
{:a [1 2 4]}
(defmacro moretimes [times body] `(let [*# #(apply * (conj %& ~times))] ~body))
#'user/moretimes
(reduce (fn [acc el] (if (> el 10) (reduced acc) (conj acc el))) [] (range))
[0 1 2 3 4 5 6 7 8 9 10]
(reduce #(if (nil? %2) %1 (conj %1 %2)) #{} [nil 1 2 3])
#{1 2 3}
(transduce identity (completing (fn [[runs run] v] (if (= v (peek run)) [runs (conj run v)] [(conj runs run) [v]]))) [[] []] [:a :a :b :b :b :b :c :c :a :d :d])
[[[] [:a :a] [:b :b :b :b] [:c :c] [:a]] [:d :d]]
(-> (map (fn [[op key val]] `(.addFilter ~(name key) ~(op {:a 1, :b 2}) ~val)) [[:a :b :c] [:e :f :g]]) (conj '(Query. "X")) (conj 'doto))
(doto (Query. "X") (user/.addFilter "b" 1 :c) (user/.addFilter "f" nil :g))
(update-in [:ol [:li] [:ol [:ol [:ol [:ol [:ol]]]]]] [1 1 1 1 1] conj [:li])
[:ol [:li {1 {1 {1 ([:li])}}}] [:ol [:ol [:ol [:ol [:ol]]]]]]
(reduce #(conj % (first %2) (second %2)) '((:a 1) (:b 2) (:c 3)))
(3 :c 2 :b :a 1)
(loop [foo 0 r []] (if (= foo 5) r (recur (inc foo) (conj r foo))))
[0 1 2 3 4]
(reduce #(if (contains? %1 %2) (reduced %1) (conj %1 %2)) [] (cycle [10 11 12]))
[10 11 12 10 11 12 10 11 12 10 11 12]
(reduce #(merge-with (partial conj []) %1 %2) [{:A 1} {:A 2} {:B 3} {:B 4}])
{:A [1 2], :B [3 4]}
(let [x (lazy-seq (conj '() (do (println "ein") 1) (do (println "twei") 2)))] (first x))
2
"ein\ntwei\n"
(let [x [1 2 3 4]] (reduce conj (subvec x 0 1) (subvec x 2)))
[1 3 4]
(loop [x 0 xs []] (if (< x 10) (recur (inc x) (conj xs x)) xs))
[0 1 2 3 4 5 6 7 8 9]
(reduce #(apply update-in %1 (take 1 %2) conj (rest %2)) {} [[:a 1] [:a 2]])
{:a (2 1)}
(defn merge [& maps] (when (some identity maps) (reduce #(conj (or %1 {}) %2) maps)))
#'user/merge
(-> {:a 1} (with-meta {:x 1}) (conj [:b 2]) (with-meta {:y 2}) (dissoc :b) meta)
{:y 2}
(reduce-kv (fn [init k v] (conj init (:uuid v))) [] {:user1 {:uuid "user1"}, :user2 {:uuid "user"}})
["user1" "user"]
(let [my-coll (range 6)] (reduce (fn [prev curr] (conj prev curr)) [(first my-coll)] (rest my-coll)))
[0 1 2 3 4 5]
(loop [acc [] new (rand)] (if (> (count acc) 3) acc (recur (conj acc new) (rand))))
[0.854089487633035 0.5745330136513881 0.6086377863231751 0.5960929344879852]
(let [a {:a []} c [{:a 2} {:a 3}]] (map (partial merge-with conj a) c))
({:a [2]} {:a [3]})
(= (quote (:e :a :b :c :d)) (conj (quote (:a :b :c :d)) :e))
true
((fn [& r] (flatten (reduce conj r))) [0 0 0] 1 [2 2 2])
(0 0 0 1 2 2 2)
(swap! (atom {}) (fn [m] (update-in m [:a] (fn [val] ((fnil conj #{}) val :b)))))
{:a #{:b}}
(let [foo #(do {%1 %2})] (conj {1 2, 3 4} (foo 3 5)))
{1 2, 3 5}
(merge-with #(if (string? %1) [%1 %2] (conj %1 %2)) {:words "hello"} {:words "world"})
{:words ["hello" "world"]}
(reduce (fn [ranges [start end :as el]] (let [[s e] (peek ranges)] (if (> start e) (conj ranges el) (conj (pop ranges) [s end])))) [[1 1]] [[1 2] [3 3] [4 5]])
[[1 2] [3 3] [4 5]]
(let [a (atom false) l (lazy-seq (swap! a not) nil)] [(first (conj l 3)) @a])
[3 true]
(reduce (fn [v k] (conj v (k {:a 1, :b 2, :c 3}))) [] [:a :b])
[1 2]
(->> {:a 1, :b 2} (map #(conj % (first %))) (apply concat) (apply hash-map))
{2 :b, :a :b}
(reduce #(if (= %2 :c) %1 (conj %1 %2)) [] [:a :b :c :d :e])
[:a :b :d :e]
(let [x [1 2 3 4]] (reduce conj (subvec x 0 3) (subvec x 3)))
[1 2 3 4]
(reduce (fn [v x] (print x) (conj v x)) ["things i printed:"] [4 5 6])
["things i printed:" 4 5 6]
"456"
(let [a (object-array 5) v (conj (vec a) :end)] (aset a 0 :hi) v)
[nil nil nil nil nil :end]
(loop [[[k v] :as i] [[0 12] [1 23] [3 65]] o []] (cond (empty? i) o (== k (count o)) (recur (next i) (conj o v)) :else (recur i (conj o 0))))
[12 23 0 65]
(-> (map (fn [[op key val]] `(.addFilter ~(name key) ~(op {:a 1, :b 2}) ~val)) [[:a :b :c] [:e :f :g]]) (conj '(doto (Query. "X"))) (conj 'doto))
(doto (doto (Query. "X")) (user/.addFilter "b" 1 :c) (user/.addFilter "f" nil :g))
(loop [x 10 acc []] (if (zero? x) (seq acc) (recur (dec x) (conj acc x))))
(10 9 8 7 6 5 4 3 2 1)
(defn foo ([x] (identity x)) ([x & xs] (conj (foo x) (doall (map foo xs)))))
#'user/foo
(let [x [1 2 3 4]] (reduce conj (subvec x 0 2) (subvec x 3)))
[1 2 4]
(for [n (range 20)] [n (class (reduce conj (array-map) (map (juxt identity identity) (range n))))])
([0 clojure.lang.PersistentArrayMap] [1 clojure.lang.PersistentArrayMap] [2 clojure.lang.PersistentArrayMap] [3 clojure.lang.PersistentArrayMap] [4 clojure.lang.PersistentArrayMap] [5 clojure.lang.PersistentArrayMap] [6 clojure.lang.PersistentArrayMap] [7 clojure.lang.PersistentArrayMap] [8 clojure.lang.PersistentArrayMap] [9 clojure.lang.PersistentHashMap] [10 clojure.lang.PersistentHashMap] [11 ...
(defn update-last [v f & args] (-> v pop (conj (apply f (peek v) args))))
#'user/update-last
(let [xs ["a" "b" "c"]] (reduce #(conj %1 (nth xs %2)) [] [0 1 2]))
["a" "b" "c"]
(reduce (fn [a v] (if (> 5 v) (reduced a) (conj a v))) #{} (range))
#{}
(reduce (fn [x y] (conj x y)) '(0) '(1 2 3 4 5))
(5 4 3 2 1 0)
(take 1 (lazy-seq (conj (lazy-seq (prn :a) (cons 2 (lazy-seq (prn :b) '(3)))) 1)))
(1)
":a\n"
(reduce conj [] (map val (sort (dissoc {0 :a, 1 :b, 2 :c, 3 :d} 2))))
[:a :b :d]
(reduce #(conj % (:a %2)) #{} [{:a 1} {:a 2} {:a 1} {:a 2}])
#{1 2}
(let [foo #(partial conj (empty %))] ((foo '(1 2 3)) 4 5 6))
(6 5 4)