((fn [func coll] (into (empty coll) (map func coll))) inc #{1 2 3})
#{2 3 4}
(-> 10 (* 2) (+ 1) (as-> x (if (even? x) x (inc x))))
22
(defn f [s] (when (seq s) (lazy-seq (cons (inc (first s)) (f (nnext s))))))
#'user/f
(let [x (iterate #(do (print "test") (inc %1)) 1)] (next x) (first x))
1
((fn lazy-recur [x] (lazy-seq (when (< x 10) (cons x (lazy-recur (inc x)))))) 0)
(0 1 2 3 4 5 6 7 8 9)
(let [v [1 2 3]] (= (take (count v) (iterate inc (first v))) v))
true
(reduce-kv (fn [acc k v] (assoc acc k (inc v))) {} {:one 1, :two 2})
{:one 2, :two 3}
(#(into {} (for [[k v] %2] [k (%1 v)])) inc {1 2, 3 4})
{1 3, 3 5}
((fn [{a :a, :keys [b], :or {b (inc a)}}] [a b]) {:a 5})
[5 6]
(apply hash-map (interleave (iterate inc 1) [{:a 1, :b 2} {:a 2, :b 3}]))
{1 {:a 1, :b 2}, 2 {:a 2, :b 3}}
(let [m {:a 1, :b 2}] (into {} (zipmap (keys m) (map inc (vals m)))))
{:a 2, :b 3}
(map (fn [xs] (map #(inc %) xs)) [[1 2 3] [2 3 4]])
((2 3 4) (3 4 5))
(letfn [(decorate [& fs] (apply juxt identity fs))] (map (decorate inc -) (range 5)))
([0 1 0] [1 2 -1] [2 3 -2] [3 4 -3] [4 5 -4])
(defn remove-elem-i [v i] (vec (concat (subvec v 0 i) (subvec v (inc i)))))
#'user/remove-elem-i
(reduce-kv (fn [m k v] (assoc m k (inc v))) {} {:a 0, :b 2})
{:a 1, :b 3}
(into {} (map (fn [[k v]] [k (inc v)]) {:a 1, :b 2, :c 3}))
{:a 2, :b 3, :c 4}
(def fac (lazy-cat [1 2 6 24 120] [(* (last fac) (inc (count fac)))]))
#'user/fac
(update-in {:a [0 1 2 3], :b [4 5 6 7]} [:a 0] inc)
{:a [1 1 2 3], :b [4 5 6 7]}
(apply (fn [a b & r] [a b (take 3 r)]) (iterate inc 0))
[0 1 (2 3 4)]
(mapcat (fn [[a b]] (vector (inc a) b)) (partition 2 [1 2 3 4]))
(2 2 4 4)
(reduce (fn [i _] (inc i)) 0 '(1 2 3 3 1))
5
(let [x (fn [& more] (take 5 more))] (apply x (iterate inc 1)))
(1 2 3 4 5)
(for [x [1 2 3 4]] {:inced (inc x), :stred (str x)})
({:inced 2, :stred "1"} {:inced 3, :stred "2"} {:inced 4, :stred "3"} {:inced 5, :stred "4"})
(zipmap (keys {:a 1, :b 2}) (map inc (vals {:a 1, :b 2})))
{:a 2, :b 3}
(defn tst-retr [i] (try (/ 5 i) (catch Exception e (tst-retr (inc i)))))
#'user/tst-retr
(let [a (atom 0) d (delay (swap! a inc))] [@d @d @d])
[1 1 1]
(let [f (let [c (atom 0)] (fn [] (swap! c inc)))] (println (f) (f)))
nil
"1 2\n"
(first (flatten [[1 2 3] [4 5 6] [7 8 (iterate inc 0)]]))
1
((fn [{b :b, a :a, :or {b 2, a (inc b)}}] [a b]) {})
[3 2]
(map (juxt inc dec) [1 2 3 4 5 6 7 8 9])
([2 0] [3 1] [4 2] [5 3] [6 4] [7 5] [8 6] [9 7] [10 8])
(reduce (fn [[i acc] el] [(inc i) (conj acc el)]) [0 []] (range 10))
[10 [0 1 2 3 4 5 6 7 8 9]]
((fn hash-by [f coll] (into {} (map (juxt f identity)) coll)) inc (range 5))
{1 0, 2 1, 3 2, 4 3, 5 4}
(take-while #(not (nil? %)) (iterate #(if (neg? %) (inc %)) -10))
(-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0)
(letfn [(myfn [x] (lazy-seq (cons x (myfn (inc x)))))] (take 5 (myfn 1)))
(1 2 3 4 5)
(let [a (atom 1) f (swap! a inc)] `(if ~f (~f)))
(if 2 (2))
(into {} (for [[k v] {:a 1, :b 2, :c 3}] [k (inc v)]))
{:a 2, :b 3, :c 4}
(let [x 3 y 42] (cond-> x (even? x) inc :else (do y)))
42
(loop [i 0] (when (< i 5) (println "i:" i) (recur (inc i))))
nil
"i: 0\ni: 1\ni: 2\ni: 3\ni: 4\n"
(def integers (letfn [(k [n] (lazy-seq (cons n (k (inc n)))))] (k 1)))
#'user/integers
(let [a (long-array [0 1 2 3 4])] (= (seq (amap a i _ (inc (aget a i)))) (seq (amap a i r (aset r i (inc (aget a i)))))))
true
(defn looper [x y] (when (< x 5) (println x) (recur (inc x) y)))
#'user/looper
(defn my-inc "add 1 or more" ([x] (inc x)) ([x y] (+ x y)))
#'user/my-inc
(-> (for [x (take 100 (iterate inc 0))] (do (println x) x)) seq boolean)
true
"0\n"
(reduce #(assoc %1 %2 (inc (get %1 %2 0))) {} ["hi" "there" "oh" "hi"])
{"hi" 2, "oh" 1, "there" 1}
(defn ranger [a b] (if (< a b) (conj [a] (ranger (inc a) b)) []))
#'user/ranger
(let [a (atom {:x {:y {:z 1}}})] (swap! a update-in [:x :y :z] inc))
{:x {:y {:z 2}}}
(map (fn [x] {:inced (inc x), :stred (str x)}) [1 2 3 4])
({:inced 2, :stred "1"} {:inced 3, :stred "2"} {:inced 4, :stred "3"} {:inced 5, :stred "4"})
(map inc (drop-last 2 [1 2 3 4 5 6 7 8 9 10]))
(2 3 4 5 6 7 8 9)
(letfn [(p [x] (prn x) x)] ((reduce comp (take 20 (cycle [p inc]))) 42))
52
"43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n"
(into {} (map (fn [[k v]] [k (inc v)]) {:first 31, :second 63, :third 127}))
{:first 32, :second 64, :third 128}