(reduce #(assoc %1 %2 (inc (%1 %2 0))) {} '(a b b c c c))
{a 1, b 2, c 3}
(do (def ^:dynamic *x* 0) (def ^:dynamic *xp1* 1) (binding [*x* 10 *xp1* (inc *x*)] *xp1*))
1
(let [a (atom 0)] (second (map (fn [_] (swap! a inc)) (filter identity (range 50)))) @a)
32
(map (comp inc int (partial * 1/3)) [1 2 3 4 5 6 7 8 9])
(1 1 2 2 2 3 3 3 4)
(let [s #{1 2 3} k 1] (conj (disj s k) (inc (get s k))))
#{2 3}
(filter identity (map #(when-not % %2) [nil nil 1 nil 1 nil] (iterate inc 0)))
(0 1 3 5)
(let [map-from-fn (fn [f ks] (into {} (map (juxt identity f) ks)))] (map-from-fn inc [7 9 12]))
{7 8, 9 10, 12 13}
(defn foo [x y] (print x y) (if (< x 9) (recur (inc x) (dec y))))
#'user/foo
(defn accumulate [f coll] (for [ind (range 1 (inc (count coll)))] (reduce f (take ind coll))))
#'user/accumulate
(let [state (atom {:plots [[1 2] [1 5]]})] (do (update-in @state [:plots 0 1] inc) @state))
{:plots [[1 2] [1 5]]}
(reduce (fn [a [k v]] (assoc a k (inc v))) {} {:a 1, :b 2, :c 3})
{:a 2, :b 3, :c 4}
(defn get-index [f x] (loop [i 0] (if (f (nth x i)) i (recur (inc i)))))
#'user/get-index
(letfn [(p [x] (prn x) x)] ((reduce comp (interleave (repeat p) (take 10 (repeat inc)))) 42))
52
"43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n"
(reduce (fn [n e] (if (even? e) (inc n) n)) 0 [0 1 2 3 4])
3
(map (comp inc #(rem % 3)) [1 2 3 4 5 6 7 8 9])
(2 3 1 2 3 1 2 3 1)
(as-> 1 $ (+ $ 3) (if (> $ 2) $ (* $ $)) (inc $))
5
((fn [f s] (reduce (fn [l v] (conj l (f v))) [] s)) inc [1 2 3])
[2 3 4]
(let [x (for [x (take 10 (iterate inc 0))] (do (println "Evaling" x) [x]))] (first x))
[0]
"Evaling 0\n"
(letfn [(juxt [& fs] #(map (fn [f] (f %)) fs))] (first ((juxt inc println) 4)))
5
(->> [1 2 3 4] (partition 2 1) (every? (fn [[a b]] (== (inc a) b))))
true
(let [{:keys [a b], :as m} {:a 1, :b 2}] (-> m (assoc :c (inc a))))
{:a 1, :b 2, :c 2}
(let [s "a/b/c/d/e"] (map #(subs s 0 (inc %)) (range 0 (count s) 2)))
("a" "a/b" "a/b/c" "a/b/c/d" "a/b/c/d/e")
(reduce (fn [acc v] (conj acc (v (last acc)))) [1] [inc #(+ 10 %)])
[1 2 12]
(loop [x 1] (do (println "x is" x) (if (even? x) :done (recur (inc x)))))
:done
"x is 1\nx is 2\n"
(let [m {:a 1, :b 2}] (into m (for [[k v] m] [k (inc v)])))
{:a 2, :b 3}
(map (fn [[k v]] [(str k k) (inc v)]) {:a 0, :b 1, :c 2})
([":a:a" 1] [":b:b" 2] [":c:c" 3])
(let [r (:repeat {:repeat 0} 0)] (if (< r 2) [r] (range 1 (inc r))))
[0]
(for [[x y] {1 2, 3 4, 5 6} item [(inc x) y]] item)
(2 2 4 4 6 6)
(let [c (atom 0) _ (with-meta (map (fn [_] (swap! c inc)) (range 100)) {})] @c)
32
(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"
(apply concat (map (fn [[x y]] [(inc x) y]) {1 2, 3 4, 5 6}))
(2 2 4 4 6 6)
(reduce (fn [totals x] (update-in totals [x] (fnil inc 0))) {} [:a :b :a :c :a])
{:a 3, :b 1, :c 1}
(defn divisors [n] (filter #(zero? (rem n %)) (range 2 (inc (/ n 2)))))
#'user/divisors
((fn [x] (map #(take (inc %) x) (range (count x)))) [1 2 3 4])
((1) (1 2) (1 2 3) (1 2 3 4))
(reduce (fn [number index] (if (even? index) (* number 2) (inc number))) 1 (range 0 3))
6
(let [{:keys [a b], :as m} {:a 1, :b 2}] (-> m (assoc :b (inc a))))
{:a 1, :b 2}
(reduce (fn [m k] (update-in m [k] (fnil inc 0))) {} [1 2 3 1 2 1])
{1 3, 2 2, 3 1}
(persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient {}) {:a 10, :b 20}))
{:a 11, :b 21}
(let [x (range 10)] (interleave (map inc (take-nth 2 x)) (map dec (take-nth 2 (rest x)))))
(1 0 3 2 5 4 7 6 9 8)
(let [a (atom 3) b (atom 4) s #{a b}] (swap! a inc) (count s))
2
(take 10 (rest (map first (iterate (fn [[a b]] [(+ a b) (inc b)]) [0 1]))))
(1 3 6 10 15 21 28 36 45 55)
(apply (fn [a b & r] [a b (map identity (take 3 r))]) (iterate inc 0))
[0 1 (2 3 4)]
((fn bit-int [bitseq] (apply + (map bit-shift-left (reverse bitseq) (iterate inc 0)))) [1 0 1 1])
11
(map (comp inc int (partial * 0.333333)) [1 2 3 4 5 6 7 8 9])
(1 1 1 2 2 2 3 3 3)
(reduce-kv (fn [m k v] (assoc m k (inc v))) {} {:a 1, :b 2, :c 3})
{:a 2, :b 3, :c 4}
(defn foo [#^int n] (loop [#^int i 1] (if (< i n) (recur (inc i)) i)))
#'user/foo
(reduce-kv (fn [m k v] (assoc m k (inc v))) {} {:a 0, :b 2, :c 42})
{:a 1, :b 3, :c 43}
(map (comp inc #(quot % 3)) [1 2 3 4 5 6 7 8 9])
(1 1 2 2 2 3 3 3 4)
(defn zigzag [n] (take n (flatten (apply map vector ((juxt reverse identity) (range 1 (inc n)))))))
#'user/zigzag
(defn tally-map [coll] (reduce (fn [h n] (assoc h n (inc (or (h n) 0)))) {} coll))
#'user/tally-map