(merge-with conj {:a #{}, :b #{}, :c #{}} {:a 1, :b 2} {:a 3, :c 1} {:a 5, :b 3})
{:a #{1 3 5}, :b #{2 3}, :c #{1}}
((fn [n] (loop [i n bits ()] (if (zero? i) bits (recur (bit-shift-right i 1) (conj bits (bit-and i 1)))))) 52)
(1 1 0 1 0 0)
(reduce (fn [S a] (if (coll? a) (into S a) (conj S a))) #{} [:hello #{:hello :world} [:gogo :gadget]])
#{:gadget :gogo :hello :world}
(defn dup [coll] (loop [remainder coll result []] (if (empty? remainder) result (recur (rest remainder) (conj result (repeat 2 (first remainder)))))))
#'user/dup
(let [a #{1 3 4 5 7} b (conj a 8)] [(b 2) (b 3) (b 5) (b 6)])
[nil 3 5 nil]
(defn path-to [target m path] (if (some #{target} (keys m)) path (for [[k v] m] (path-to target v (conj path k)))))
#'user/path-to
(let [vs [[1 2] [3 4] [5 6]] [before after] (split-at 1 vs)] (apply conj (vec before) [7 8] [9 10] after))
[[1 2] [7 8] [9 10] [3 4] [5 6]]
(let [in [{:hello 1} {:hello 3} {:hello 4}] ks (distinct (mapcat keys in)) init (zipmap ks (repeat []))] (apply merge-with conj init in))
{:hello [1 3 4]}
((fn [coll] (boolean (reduce (fn [s e] (if (contains? s e) (reduced false) (conj s e))) #{} coll))) [1 2 3 4])
true
(let [in [{:hello [1]} {:hello [3]} {:hello [4]}] ks (distinct (mapcat keys in)) init (zipmap ks (repeat []))] (apply merge-with conj init in))
{:hello [[1] [3] [4]]}
(loop [[x & xs] (range 20) acc [] sum 0] (if (< sum 8) (recur xs (conj acc x) (+ sum x)) acc))
[0 1 2 3 4]
(reduce #(if (= %2 (peek %1)) %1 (conj %1 %2)) [] [1 2 4 4 5 5 5 5 6 6 8])
[1 2 4 5 6 8]
(let [registered (atom [])] (defn register [f & args] (swap! registered conj [f args])) (defn fire [] (doseq [[f args] @registered] (apply f args))))
#'user/fire
(defn comb [r m p] (if (> m 0) (mapcat #(comb (disj r %) (dec m) (conj p %)) r) [p]))
#'user/comb
((fn group-by-2 [s] (if (even? (count s)) (partition 2 s) (conj (partition 2 (rest s)) (seq [(first s) (second s)])))) (range 13))
((0 1) (1 2) (3 4) (5 6) (7 8) (9 10) (11 12))
(reduce (fn [[acc time] [dur freq]] [(conj acc [time freq]) (+ time dur)]) [[] 0] [[1 :a] [4 :b] [3 :c] [1 :d]])
[[[0 :a] [1 :b] [5 :c] [8 :d]] 9]
(reduce (fn [s x] (if (s x) (reduced x) (conj s x))) #{} [1 2 3 4 5 1 7 8])
1
(reduce (fn [moves word] (conj moves (({"next" inc, "prev" dec} word) (peek moves)))) [0] (clojure.string/split "next prev next next" #" "))
[0 1 0 1 2]
(reduce (fn [[m l] n] (if (<= m 100) [(* m n) (conj l n)] (reduced l))) [1 []] (range 1 100))
[1 2 3 4 5]
(filter (complement nil?) (reduce #(conj %1 (when (not= (last %1) %2) %2)) [] [1 1 2 3 3 2 2 3]))
(1 2 3 2 3)
(map (fn [x] (into (empty x) (conj (seq x) :a))) [[:b :c :d] '(:b :c :d) #{:b :c :d}])
([:a :b :c :d] (:d :c :b :a) #{:a :b :c :d})
(apply conj [] (for [x (range 2) y (range 2)] [x y]) (for [x (range 3 5) y (range 3 5)] [x y]))
[([0 0] [0 1] [1 0] [1 1]) [3 3] [3 4] [4 3] [4 4]]
(let [session {:task "first task"}] (assoc session :task (if (vector? (:task session)) (conj (:task session) "second task") (vector (:task session) "second task"))))
{:task ["first task" "second task"]}
(apply merge-with #(if (list? %1) (conj %1 %2) (list %1 %2)) (map (partial apply hash-map) [["x" 4] ["x" 5] ["y" 6]]))
{"x" (4 5), "y" 6}
(reduce (fn [a [k v]] (update-in a [k] (fnil conj []) v)) {} (mapcat (partial map identity) [{:a 1} {:b 2, :a 2} {:b 2}]))
{:a [1 2], :b [2 2]}
(defn update-stats [args] (let [m (apply hash-map args)] (fn [state] (reduce (fn [s [k vs]] (apply update-in s [k] conj vs)) state m))))
#'user/update-stats
((fn [x] (map vector (conj (iterate (partial + 10) 11) 0) (concat (take-while (partial >= x) (iterate (partial + 10) 10)) [x]))) 55)
([0 10] [11 20] [21 30] [31 40] [41 50] [51 55])
(loop [x (range 20) acc [] sum 0] (if (< sum 8) (recur (next x) (conj acc (first x)) (+ sum (first x))) acc))
[0 1 2 3 4]
(defn make-connection-thingy [] (let [connections (atom [])] {:onconnect (fn [x] (swap! connections conj x)), :onmessage (fn [x] (println x)), :current-connections (fn [] (deref connections))}))
#'user/make-connection-thingy
(type (conj (array-map 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8) [9 9]))
clojure.lang.PersistentHashMap
(let [h {:a 1, :b 2} f (fn [f v] (reduce #(conj %1 [(key %2) (f (val %2))]) {} v))] (f inc h))
{:a 2, :b 3}
(merge-with (fn [a b] (conj (if (vector? a) a [a]) b)) {:a 1, :b 2, :c 3} {:a 3, :b 5, :d 7})
{:a [1 3], :b [2 5], :c 3, :d 7}
(map #(= (% '(1 2 3)) (% [1 2 3])) [identity pop peek #(conj % 0) #(cons 0 %)])
(true false false false true)
(defn partitioner [x coll] (loop [remainder coll result []] (if (>= (count remainder) x) (recur (drop x remainder) (conj result (take x remainder))) result)))
#'user/partitioner
(let [a {1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7}] [(class (conj a [8 8])) (class a)])
[clojure.lang.PersistentArrayMap clojure.lang.PersistentArrayMap]
(let [nest {:a {:b :makes, :c :takes}, :b {:c :takes}, :c {:a :makes}}] (reduce #(conj %1 [(key %2) (keys (val %2))]) {} nest))
{:a (:b :c), :b (:c), :c (:a)}
(reduce (fn [m [k v]] (update m k (fnil conj #{}) v)) {} '[[a 0] [b 1] [b 2] [a 0] [c 3]])
{a #{0}, b #{1 2}, c #{3}}
((fn choices [items n] (if (zero? n) [[]] (for [choice (choices items (dec n)) item items] (conj choice item)))) '#{black white} 3)
([black black black] [black black white] [black white black] [black white white] [white black black] [white black white] [white white black] [white white white])
(apply conj (sort-by second {:a 3, :b 1, :c 5, :d 7, :e 8, :f 9, :g 10, :h 11, :i 12}))
[:b 1 [:a 3] [:c 5] [:d 7] [:e 8] [:f 9] [:g 10] [:h 11] [:i 12]]
(update-in [{:data {:people [{:id 1, :projects [{:id 1, :hours 20}]}]}, :end_date "2014-12-14T05:00:00Z", :start_date "2014-12-01T05:00:00Z"}] [0 :data :people] conj {:id 2, :projects []})
[{:data {:people [{:id 1, :projects [{:hours 20, :id 1}]} {:id 2, :projects []}]}, :end_date "2014-12-14T05:00:00Z", :start_date "2014-12-01T05:00:00Z"}]
(reduce (fn [m [a b]] (let [item (m a [])] (assoc m a (conj item b)))) {} '[[foo bar] [foo zonk] [bar foo]])
{bar [foo], foo [bar zonk]}
(mapcat (fn [[p & s]] (map #(conj % p) s)) '((a (b c) (c b)) (b (a c) (c a))))
((a b c) (a c b) (b a c) (b c a))
(defn perm [r m p] (if (> m 0) (mapcat #(perm (disj r %) (dec m) (conj p %)) r) [p]))
#'user/perm
(reduce (fn [m [k v]] (assoc m k (conj (m k #{}) v))) {} (concat {:a 1, :b 2} {:a 1, :b 3}))
{:a #{1}, :b #{2 3}}
(let [book {:title "some book", :authors [{:name "some author"} {:name "other author"}]} new-author {:name "added author"}] (assoc book :authors (conj (:authors book) new-author)))
{:authors [{:name "some author"} {:name "other author"} {:name "added author"}], :title "some book"}
((fn two-parts ([coll] (two-parts coll [] [])) ([coll a b] (if (empty? coll) [a b] (recur (rest coll) (conj b (first coll)) a)))) (range 10))
[[1 3 5 7 9] [0 2 4 6 8]]
(reduce (fn [m [k v]] (update-in m [k] (fn [e] (if (seq e) (conj e v) [v])))) {} (for [i (range 10)] [:a i]))
{:a [0 1 2 3 4 5 6 7 8 9]}
(loop [x {:foo {:bar []}} y 0] (let [y (inc y)] (if (< y 10) (recur (update-in x [:foo :bar] conj y) y) x)))
{:foo {:bar [1 2 3 4 5 6 7 8 9]}}
((fn structure [s] (mapcat (fn [x] (if (coll? x) (conj (empty x) (structure x)) ())) s)) '[1 2 (3 4) (5 (6 7))])
(() (()))
(reduce (fn [m [k v]] (update-in m [k] #(conj % v))) {} (map #(clojure.string/split % #"\s") ["key value" "key2 value2" "key2 anothervalue2"]))
{"key" ("value"), "key2" ("anothervalue2" "value2")}