(letfn [(endpoints [n m] (let [chunk (int (/ n m))] (loop [r [] prev 0 curr chunk] (if (> curr n) (conj r n) (recur (conj r prev) curr (+ curr chunk))))))] (endpoints 100 3))
[0 33 66 100]
(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 3] [3 3] [3 5]])
[[1 5]]
(reduce (fn [m [k v]] (update-in m [k] conj v)) {} (for [i (range 10)] [:a i]))
{:a (9 8 7 6 5 4 3 2 1 0)}
(reduce #(update-in %1 [(first %2)] (fnil conj []) (second %2)) {} [[:a 1] [:a 2] [:b 3]])
{:a [1 2], :b [3]}
(reduce (fn [result element] (if (< element 10) (conj result (* 3 element)) result)) [] (range 20))
[0 3 6 9 12 15 18 21 24 27]
(-> (sorted-set [3 2] [1 2 3] [4]) (disj [3 2]) (conj [3 2 1 0]))
#{[1 2 3] [3 2 1 0] [4]}
((fn [f s] (reduce (fn [l v] (conj l (f v))) [] s)) inc [1 2 3])
[2 3 4]
(next (reduce (fn [v x] (conj v (+ x (last v)))) [0] [3 3 4 3]))
(3 6 10 13)
(reduce (fn [m [k v]] (update-in m [k] conj v)) {} [[:a :b] [:a :c] [:d :e]])
{:a (:c :b), :d (:e)}
(reduce #(apply conj %1 %2) #{} [[1 2 3 4] [3 4 5 6 7]])
#{1 2 3 4 5 6 7}
(let [s #{1 2 3} k 1] (conj (disj s k) (inc (get s k))))
#{2 3}
(reduce #(if (contains? %1 %2) (reduced %1) (conj %1 %2)) [] (cycle [1 2 3 4]))
[1 2 3 4]
((fn [fname & args] (eval (conj () (vec args) (read-string fname) 'apply))) "+" 2 3 4)
9
(reduce (fn [acc v] (conj acc (v (last acc)))) [1] [inc #(+ 10 %)])
[1 2 12]
(loop [a 10 acc nil] (if (zero? a) acc (recur (dec a) (conj acc a))))
(1 2 3 4 5 6 7 8 9 10)
(loop [n 5 v []] (if (zero? n) (seq v) (recur (dec n) (conj v n))))
(5 4 3 2 1)
(transduce (comp (map (fn [x] (println x) true)) (take-while true?)) conj [] (map inc (range 4)))
[true true true true]
"1\n2\n3\n4\n"
(let [a '(a list) r (atom a)] (swap! r conj 'something) [a @r r])
[(a list) (something a list) #object [clojure.lang.Atom 0x2aa81bde {:status :ready, :val (something a list)}]]
(defn vinsert [e index v] (apply conj (subvec v 0 index) e (subvec v index)))
#'user/vinsert
(defn foo [c] (reduce #(conj %1 (+ (last %1) %2)) [(first c)] (rest c)))
#'user/foo
(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 3] [4 5] [7 9] [8 8]])
[[1 3] [4 5] [7 8]]
((fn f [x] (if x (conj (rest x) (first x)) nil)) '(1 2 3 4))
(1 2 3 4)
(let [append-to-self (comp (partial apply conj) (juxt (fnil identity []) identity))] (map append-to-self [[] [1] [2 3] nil]))
([[]] [1 [1]] [2 3 [2 3]] [nil])
(for [n (range 14 18)] [n (class (reduce conj (array-map) (map (juxt identity identity) (range n))))])
([14 clojure.lang.PersistentHashMap] [15 clojure.lang.PersistentHashMap] [16 clojure.lang.PersistentHashMap] [17 clojure.lang.PersistentHashMap])
(reduce (fn [ranges [start end :as el]] (let [[s e] (peek ranges)] (if (> start (inc e)) (conj ranges el) (conj (pop ranges) [s end])))) [[1 1]] [[1 2] [3 3] [4 5]])
[[1 5]]
(let [a (atom [])] (clojure.walk/postwalk #(swap! a conj %) '(+ a (- b c))) @a)
[+ a - b c ([+ a -] [+ a - b] [+ a - b c]) ([+] [+ a] [+ a - b c ([+ a -] [+ a - b] [+ a - b c])])]
(let [config {:use-https true, :https-port 443}] (cond-> #{[:a :b :c]} (:use-https config) (conj (:https-port config))))
#{443 [:a :b :c]}
(reduce (fn [prev new] (take 2 (sort > (conj prev new)))) [] [1 29 9 4 10])
(29 10)
(let [v [1 2 3 4]] (apply conj (subvec v 0 1) 8 (subvec v 1)))
[1 8 2 3 4]
(let [adam (atom [])] (do (print adam) (print @adam) (swap! adam conj :eve) (print adam) (print @adam)))
nil
"#object[clojure.lang.Atom 0x44179b1f {:status :ready, :val []}][]#object[clojure.lang.Atom 0x44179b1f {:status :ready, :val [:eve]}][:eve]"
(reduce (fn [m [k v]] (update-in m [k] (fnil conj []) v)) {} (for [i (range 10)] [:a i]))
{:a [0 1 2 3 4 5 6 7 8 9]}
(loop [m -9001 acc ()] (if (zero? m) acc (recur (quot m 10) (conj acc (rem m 10)))))
(-9 0 0 -1)
((comp (partial apply reduce conj) (juxt (comp first list) (comp range second list))) [:a :b :c] 4)
[:a :b :c 0 1 2 3]
(print (apply str (flatten (repeatedly 1 (fn [] (conj (shuffle (concat (repeat 40 "/") (repeat 40 "\\"))) "\n"))))))
nil
"//\\\\/\\/\\////\\\\\\///////\\\\\\//\\//\\\\////\\\\\\\\/\\/\\/\\/\\\\/\\\\\\\\/\\///\\///\\//\\\\\\/\\\\\\\\/\\\\\\\\/\n"
(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 3] [4 5] [7 9] [6 6]])
[[1 3] [4 5] [7 6]]
(reduce #(if (> %2 (last (last %1))) (update-in %1 [(dec (count %1))] conj %2) (conj %1 [%2])) [[(first '(2 0 1 2 0 1))]] (rest '(2 0 1 2 0 1)))
[[2] [0 1 2] [0 1]]
(reduce (fn [m [k v]] (update-in m [(keyword k)] conj v)) {} [["foo" "bar"] ["foo" "baz"] ["bar" "qux"]])
{:bar ("qux"), :foo ("baz" "bar")}
(defn add-peak [peak peaks] (if (>= (reduce + peak) (reduce + (first peaks))) (conj peaks peak) peaks))
#'user/add-peak
(loop [a () b [1 2 3]] (if (empty? b) a (recur (conj a (peek b)) (pop b))))
(1 2 3)
(merge-with #(if (string? %1) [%1 %2] (conj %1 %2)) {:words "hello"} {:words "world"} {:nothing "nothing"})
{:nothing "nothing", :words ["hello" "world"]}
(apply conj {} (map (juxt :key :value) [{:key "the key", :value "the value"} {:key :a, :value :b}]))
{:a :b, "the key" "the value"}
(let [x [] y (conj x '(filter #(= 3 %) (range 1000)))] (comment "blah blah"))
nil
(map (comp #(conj % [5 6]) #(% 1 2 3 4)) [list vector hash-map])
(([5 6] 1 2 3 4) [1 2 3 4 [5 6]] {1 2, 3 4, 5 6})
(update-in {:a {:deeply {:nested ['structure 'with 'a 'vector 'inside]}}} [:a :deeply :nested] conj 'inside 'of 'it)
{:a {:deeply {:nested [structure with a vector inside inside of it]}}}
(reduce #(merge-with conj %1 %2) {:a [], :b []} [{:a 1} {:b 2, :a 2} {:b 2}])
{:a [1 2], :b [2 2]}
(reduce #(%2 % '(sdegutis is)) '{(sdegutis is) (awesome), (sdegutis is-not) (lame)} [get conj])
((sdegutis is) awesome)
(= '(:a :b :c :d :e 0) (conj '(:a :b :c :d :e) 0))
false
(let [m (memoize conj)] [(m [1 2 3] 4) (m (list 1 2 3) 4)])
[[1 2 3 4] [1 2 3 4]]
(->> (map :a [{:a 1} {:a 2}]) (filter #(= 1 %)) (#(conj % 2)))
(2 1)
(transduce (map (fn [[k v]] [k [v (inc v)]])) conj {} {:a 4, :b 5, :c 6})
{:a [4 5], :b [5 6], :c [6 7]}