(let [r 1 g 90 b 180] (-> r (bit-or (bit-shift-left g 8)) (bit-or (bit-shift-left b 16))))
11819521
(-> {:foo [1 2]} (update-in [:foo] conj 3) (update-in [:foo 1] + 10) (update-in [:foo] (partial mapv inc)))
{:foo [2 13 4]}
(->> (ns-map *ns*) (map second) (filter #(= (-> % meta :ns str) "somnium.congomongo")) (map #(ns-unmap *ns* %)))
()
(try (doseq [y [1]] (throw (ex-info "some-error" {:val y}))) (catch clojure.lang.ExceptionInfo ex (println (.getMessage ex) (-> ex ex-data :val))))
nil
"some-error 1\n"
(let [v '[a b c d e]] (-> (subvec v 0 2) (conj 'X) (into (subvec v 2))))
[a b X c d e]
(letfn [(!-?> [&$ &!] (if (> &! 1) (!-?> (->> &$ (* &!)) (-> &! dec)) &$))] (!-?> 1 5))
120
(letfn [(f [s] (reduce (fn [acc _] (conj acc (take (-> acc count inc) s))) [] s))] (f [1 2 3]))
[(1) (1 2) (1 2 3)]
(defn tree-dissoc [root key] (-> (reduce (fn [root' child] (update-in root' [child] tree-dissoc key)) root (:children root)) (dissoc key)))
#'user/tree-dissoc
(if-let [res ((comp peek first) (re-seq #"foo=(\d+)" "this is foo=10"))] #_=> (-> res Integer/parseInt inc) #_=> nil)
11
(-> {:a [1 2 3]} (as-> x (assoc x :avg_a (let [r (:a x)] (/ (apply + r) (count r))))))
{:a [1 2 3], :avg_a 2}
(->> (ns-map *ns*) (map second) (filter #(= (-> % meta :ns str) "somnium.congomongo")) (map #(ns-unmap *ns* (.sym %))))
()
(reduce-kv (fn [m k v] (assoc m k (-> v (clojure.string/replace #"^nora$" "bob") (clojure.string/replace #"ra" "ma")))) {} {:a "nora", :b "sara"})
{:a "bob", :b "sama"}
((-> [! $] #(+ (*) (* ! $))) (+ (*) (*)) (#(* % % %) (+ (*) (*))))
17
(defn foo [x] (let [add-5? (fn [y] (if (> x 8) (conj y 5) y))] (-> [3] (conj 4) add-5?)))
#'user/foo
(apply concat (-> (range 10) (((fn [f] (fn [a b] (f b a))) map) (fn [x] (if (even? x) [x] [])))))
(0 2 4 6 8)
(-> (clojure.string/split-lines "01 02 03\n04 05 06") (#(map (fn [x] (clojure.string/split x #"\s+")) %)) flatten (#(map read-string %)))
(1 2 3 4 5 6)
((fn [v ks] (apply assoc v (mapcat #(-> [% (v %2)]) ks (reverse ks)))) [:a :b :c] [0 1])
[:b :a :c]
(vector (def ^:dynamic *modulus* 10) (defn f [x] (-> x (inc) (mod *modulus*))) (binding [*modulus* 3] (take 3 (iterate f 1))))
[#'user/*modulus* #'user/f (1 2 3)]
(defn map-walk [m] (if (map? m) (reduce (fn [a [k v]] (assoc a (-> k name keyword) (map-walk v))) {} m) m))
#'user/map-walk
(-> {:a 1, :c 3} (#(if true (assoc % :b 2) %)) (#(if true (assoc % :d 4) %)))
{:a 1, :b 2, :c 3, :d 4}
(-> (with-meta 'cons {:car 1, :cdr (with-meta 'cons {:car 2, :cdr (with-meta 'cons {:car 3, :cdr 'nil})})}) meta :cdr meta :car)
2
(-> '[win lose lose] (as-> [a b c] [b a c] [c b a] [a c b] [b c a]))
[lose win lose]
(let [r 255 g 255 b 255] (-> (bit-or r -16777216) (bit-or (bit-shift-left g 8)) (bit-or (bit-shift-left b 16))))
-1
(do (defmacro map-> [coll & clauses] (let [g (gensym)] `(for [~g ~coll] (-> ~g ~@clauses)))) (map-> [1 2 3] inc even?))
(true false true)
(defn swap-key [coll a b] (let [av (coll a) bv (coll b)] (-> coll (assoc a bv) (assoc b av))))
#'user/swap-key
(defmacro sym-meta "Despite Bronsa" [sym] (let [immediate (meta sym) env (-> &env (find sym) (some-> key) meta)] (merge env immediate)))
#'user/sym-meta
(let [r 255 g 255 b 255] (-> r (bit-or (bit-shift-left g 8)) (bit-or (bit-shift-left g 8)) (bit-or (bit-shift-left b 16))))
16777215
(let [nodes (range 6) decorators (-> (map (fn [a b] a) (repeat "|--") (rest nodes)) (concat ["`--"]))] (map str nodes decorators))
("0|--" "1|--" "2|--" "3|--" "4|--" "5`--")
(let [r 0 g 0 b 0] (-> r (bit-or (bit-shift-left g 8)) (bit-or (bit-shift-left g 8)) (bit-or (bit-shift-left b 16))))
0
(let [r 1 g 90 b 180] (-> r (bit-or (bit-shift-left g 8)) (bit-or (bit-shift-left g 8)) (bit-or (bit-shift-left b 16))))
11819521
(let [a [[1 12] [2 23] [5 65]] m (into (sorted-map) a)] (map m (-> a last first inc range) (repeat 0)))
(0 12 23 0 0 65)
(let [sds [[:a :b :c] [:d :e :f :g]]] (doseq [i (range (count sds))] (-> ((vec sds) i) rest rest first println)))
nil
":c\n:f\n"
(let [nodes (range 6) decorators (-> (map (fn [a b] a) (repeat "|--") (rest nodes)) (concat ["`--"]))] (map str decorators nodes))
("|--0" "|--1" "|--2" "|--3" "|--4" "`--5")
(let [db {:next-id 1, :rows {}} id (:next-id db) new-row "fred"] (-> db (assoc :next-id (inc id)) (update-in [:rows] assoc id new-row)))
{:next-id 2, :rows {1 "fred"}}
(-> 1 inc inc inc inc inc inc inc inc inc inc inc inc inc inc inc inc inc inc inc inc inc)
22
(letfn [(lookup [x y v] (-> (nth v x) (nth y)))] (lookup 1 1 [[1 2 3] [4 5 6] [7 8 9]]))
5
(nth (-> '[win lose lose] (as-> [a b c] [b a c] [c b a] [a c b] [b c a])) 1)
win
(defmacro with-letters [expr] `(let [~@(mapcat (fn [i] (let [sym (-> i char str symbol)] [sym (list 'quote sym)])) (range 97 123))] ~expr))
#'user/with-letters
(defn move-up [v i] (let [pos (.indexOf v i)] (if (pos? pos) (-> v (assoc pos (v (dec pos))) (assoc (dec pos) i)) v)))
#'user/move-up
(let [divisors [[15 "fizzbuzz"] [3 "fizz"] [5 "buzz"]]] (defn fizzbuzz [n] (-> (first (for [[r s] divisors :when (zero? (mod n r))] s)) (or (str n)))))
#'user/fizzbuzz
((fn [nums] (reduce (fn [m x] (-> m (update :min min x) (update :max max x))) {:min (first nums), :max (first nums)} (rest nums))) (range 10))
{:max 9, :min 0}
(let [v [1 2 3 1 2 4]] (reduce (fn [a b] (if (< (peek a) b) (conj a b) a)) (-> v (get 0) vector) v))
[1 2 3 4]
(defn ba [s [f & r]] (if f (let [y (gensym)] `(-> ~(peek s) ~f (as-> ~y ~(ba (conj s y) r)))) s))
#'user/ba
(let [incw (fn [f] #(inc (f %))) firstw (fn [f] #(first (f %))) stack (-> identity firstw incw)] (stack [0 2 4 6]))
1
(let [incw (fn [f] #(f (inc %))) firstw (fn [f] #(f (first %))) stack (-> identity incw firstw)] (stack [0 2 4 6]))
1
(reduce #(let [i (rand-int %2) j (dec %2)] (-> %1 (assoc i (%1 j)) (assoc j (%1 i)))) [1 2 3 4 5] (range 5 1 -1))
[1 5 4 3 2]
(defmacro heck-> ([x] x) ([x form1] `(let [x1# ~x x2# (-> x1# ~form1)] (if (nil? x2#) x1# x2#))) ([x form1 & more] `(heck-> (heck-> ~x ~form1) ~@more)))
#'user/heck->
(reduce (fn [m {x :a, y :b}] (update-in m [x] #(-> %1 (or 0) (+ %2)) y)) {} [{:a "x", :b 1} {:a "y", :b 1} {:a "x", :b 1}])
{"x" 2, "y" 1}
(-> (map (fn [[op key val]] `(.addFilter ~(name key) ~(op {:a 1, :b 2}) ~val)) [[:a :b :c] [:e :f :g]]) (conj '(doto (Query. "X")) (conj 'doto)))
(doto (doto (Query. "X")) (user/.addFilter "b" 1 :c) (user/.addFilter "f" nil :g))
(let [cunescape (fn [s] (apply str (map #(-> %1 (clojure.string/replace "\\r" "\r") (clojure.string/replace "\\n" "\n") (clojure.string/replace "\\t" "\t") (clojure.string/replace #"\\(.)" "$1")) (re-seq #"\\.|[^\\]*" s))))] (cunescape "test\\r\\n\\t\\'"))
"test\r\n\t'"