(#(map (fn [i _] (take i %)) (iterate inc 1) %) [1 2 3 4])
((1) (1 2) (1 2 3) (1 2 3 4))
(let [x (atom 1) _ (do (swap! x inc) (swap! x * 2) 123)] @x)
4
(loop [x 3] (let [y (* x x)] (if (> y 20) y (recur (inc x)))))
25
(defn stringectomy [st idx] [(.charAt st idx) (str (subs st 0 idx) (subs st (inc idx)))])
#'user/stringectomy
(let [x 10 x (/ x 5) x (replicate x x) x (map inc x)] x)
(3 3)
(loop [i 0 j 5] (if (> i j) [i j] (recur (inc i) (dec j))))
[3 2]
(into {} (map (fn [[k v]] [(str k "-san") (inc v)]) {:a 1, :b 2, :c 3}))
{":a-san" 2, ":b-san" 3, ":c-san" 4}
((fn [x y] (if (= (- x y) 0) 0 (recur x (inc y)))) 5 1)
0
(map #(- %1 (* %2 250)) '(0 250 500 750 1000) (iterate inc -1))
(250 250 250 250 250)
(-> [a b] (fn (assoc a b (-> b (a 0) inc))) (reduce {} "foo bar baz"))
{\space 2, \a 2, \b 2, \f 1, \o 2, \r 1, \z 1}
(reduce #(if (= %2 1) (inc %1) %1) 0 [1 2 3 2 3 1])
2
(let [fns [inc #(mod % 100) #(* % %)]] ((apply comp (reverse fns)) 104))
25
(update-in {:a [0 1 2 3], :b [4 5 6 7]} [:a] (fn [x] (map inc x)))
{:a (1 2 3 4), :b [4 5 6 7]}
((fn all-subvecs [xs] (cons [] (mapcat #(partition % 1 xs) (range 1 (inc (count xs)))))) (range 4))
([] (0) (1) (2) (3) (0 1) (1 2) (2 3) (0 1 2) (1 2 3) (0 1 2 3))
(reduce (fn [acc path] (update-in acc path (fnil inc 0))) {} '((a b c) (a b d)))
{a {b {c 1, d 1}}}
(let [funcs {:a inc, :b dec} values {:b 5, :a 10}] (merge-with #(%1 %2) funcs values))
{:a 11, :b 4}
(clojure.walk/postwalk #(if (number? %) (inc %) %) {[1 1] :a, :b {1 1, 2 [2 2]}})
{:b {2 2, 3 [3 3]}, [2 2] :a}
(assoc {1 0, 2 0, 3 0} 2 (inc ({1 0, 2 0, 3 0} 2 0)))
{1 0, 2 1, 3 0}
(let [state (atom {:plots [[1 2] [1 5]]})] (do (swap! state update-in [:plots 0 1] inc) @state))
{:plots [[1 3] [1 5]]}
(map #(%1 %2) (cycle [inc identity]) [1 2 3 4 5 6 7 8 9 10])
(2 2 4 4 6 6 8 8 10 10)
(let [m {:x 1, :y 2}] (reduce (fn [res [k v]] (assoc res k (inc v))) {} m))
{:x 2, :y 3}
(let [v [:a :b :c] i 1] (into (subvec v 0 i) (subvec v (inc i))))
[:a :c]
(let [i 2] (reduce (fn [c p] (if (p i) (inc c) c)) 0 [odd? even? pos?]))
2
(reduce (fn [m [p f]] (update-in m p f)) {:a 1, :b 2} {[:a] inc, [:b] dec})
{:a 2, :b 1}
((fn f [n [[k v] :as i]] (lazy-seq (when i (if (== k n) (cons v (f (inc n) (next i))) (cons 0 (f (inc n) i)))))) 0 [[0 12] [1 23] [3 65]])
(12 23 0 65)
(take 26 ((fn [start] (filter #(= (seq (str %)) (reverse (str %))) (iterate inc start))) 0))
(0 1 2 3 4 5 6 7 8 9 11 22 33 44 55 66 77 88 99 101 111 121 131 141 151 161)
(let [xs (lazy-seq (iterate inc 0)) pre (realized? xs) x (first xs) post (realized? xs)] [pre post])
[false true]
(let [pred #{4} coll (range)] (reduce #(if (pred %2) (reduced %1) (inc %1)) 0 coll))
4
(defn length ([lst] (length lst 0)) ([lst count] (if (seq lst) (recur (rest lst) (inc count)) count)))
#'user/length
(let [m {:a 1, :b 2, :c 3}] (reduce #(update-in %1 [%2] inc) m (keys m)))
{:a 2, :b 3, :c 4}
(let [create-counter (fn [] (let [cnt (atom 0)] (fn [] (swap! cnt inc)))) counter (create-counter)] (repeatedly 10 counter))
(1 2 3 4 5 6 7 8 9 10)
(loop [i 0 j 50] (if (> i j) [i j] (recur (inc i) (/ j 2))))
[4 25/8]
(map (comp inc #(quot % 3) dec) [1 2 3 4 5 6 7 8 9])
(1 1 1 2 2 2 3 3 3)
(do (def ^:const x 1) (defn foo [] (inc x)) (print (foo)) (def x 2) (print (foo) x))
nil
"22 2"
(#(mapv (fn [i _] (vec (take i %))) (iterate inc 1) %) [1 2 3 4])
[[1] [1 2] [1 2 3] [1 2 3 4]]
(filter #(= 0 (mod % 3)) (map #(* 2 %) (take 1000 (iterate inc 1))))
(6 12 18 24 30 36 42 48 54 60 66 72 78 84 90 96 102 108 114 120 126 132 138 144 150 156 162 168 174 180 186 192 198 204 210 216 222 228 234 240 246 252 258 264 270 276 282 288 294 300 306 312 318 324 330 336 342 348 354 360 366 372 378 384 390 396 402 408 414 420 426 432 438 444 450 456 462 468 474 480 486 492 498 504 510 516 522 528 534 540 546 552 558 564 570 576 582 588 594 600 606 612 618 624 ...
(vec (mapcat #(if (not= %2 2) (list %1)) [1 2 2 3] (iterate inc 0)))
[1 2 3]
(first (apply concat (repeatedly (fn [] (do (println "foo") (iterate #(do (println %) (inc %)) 0))))))
0
"foo\nfoo\nfoo\nfoo\n"
(do (def n 0) (loop [] (def n (inc n)) (println n) (if (< n 10) (recur))))
nil
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
(loop [x 0 y 0] (if (> x 100) x (recur (+ x y) (inc y))))
105
(map (fn [f & args] (apply f args)) (cycle [inc dec]) [1 2 3 4 5])
(2 1 4 3 6)
(for [a (range 3) b (range 3) :when (= a (inc b))] {:a a, :b b})
({:a 1, :b 0} {:a 2, :b 1})
(loop [i 0 t 0] (if (> i 10) t (recur (inc i) (+ i t))))
55
(let [[a b c d] (map inc [1 2 3 4])] (println a b c d))
nil
"2 3 4 5\n"
(reduce-kv (fn [m k v] (assoc m k (inc v))) {} {:a 0, :b 1, :c 2})
{:a 1, :b 2, :c 3}
(macroexpand '(-> [1 2 3] '(map inc) first - dec (+ 3) (min 5)))
(min (+ (dec (- (first (quote [1 2 3] (map inc))))) 3) 5)
(map (juxt (comp dec :a) (comp inc :b)) [{:a 1, :b 2} {:a 3, :b 4}])
([0 3] [2 5])
(into [] (map (fn [v] (update-in v [:a] inc)) [{:a 1, :b 2} {:a 3, :b 4}]))
[{:a 2, :b 2} {:a 4, :b 4}]
(letfn [(without [s n] (concat (take n s) (drop (inc n) s)))] (without (range 10) 4))
(0 1 2 3 5 6 7 8 9)
(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]}