(let [v [0 1 2 3] i 2] (vec (concat (subvec v 0 i) (subvec v (+ i 1)))))
[0 1 3]
(let [{{:keys [mother father], :as parents} :parents} {:first "John", :last "Doe", :parents {:mother "Alicia", :father "George"}}] [parents mother father])
[{:father "George", :mother "Alicia"} "Alicia" "George"]
(let [a '(1 2 3) b '(4 5 6)] (for [x a y b] (println x y)))
(nil nil nil nil nil nil nil nil nil)
"1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n"(let [m {:a {:b {:c 1}}} x 2] (if (nil? x) m (update-in m [:a :b :d] (constantly x))))
{:a {:b {:c 1, :d 2}}}
(apply merge (for [[k v] (partition 2 ["a_b_c" 1 "d" 2])] (let [ks (.split k "_")] (assoc-in {} ks v))))
{"a" {"b" {"c" 1}}, "d" 2}
(let [hour-a 23 hour-b 20] (mod (- (+ (if (< hour-a (+ 12 hour-b)) -24 24) hour-b) hour-a) 24))
21(let [return (promise)] (if false (deliver return 0)) (if nil (deliver return 1)) (if true (deliver return 2)) @return)
2(let [coll [1 2 3] f (fn [pred coll] (or (first (filter pred coll)) (first coll)))] (f even? coll))
2(let [a (seq [1 2 3]) b '(1 2 3)] (list (= a b) (sequential? a) (sequential? b)))
(true true true)
(defn foo2 [n] (let [n (int n)] (loop [i (int 0)] (if (< i n) (recur (inc i)) i))))
#'user/foo2
(let [[a [_ & b]] (split-with #(not= 3 %) [1 2 3 4 5 6])] (concat a b))
(1 2 4 5 6)
(let [orig {1 "one", 2 "two", 3 "three"}] [orig (zipmap (keys orig) (map #(* -1 %) (keys orig)))])
[{1 "one", 2 "two", 3 "three"} {1 -1, 2 -2, 3 -3}]
(defn extract-rand [v] (let [n (rand-int (count v))] [(get v n) (into [] (concat (take n v) (drop (inc n) v)))]))
#'user/extract-rand
(let [v [64 70 200 90]] (map (fn [a b] a) v (concat (take-while #(< % 200) v) [::extra])))
(64 70 200)
(let [{{mother :mother, father :father, :as parents} :parents} {:first "John", :last "Doe", :parents {:mother "Alicia", :father "George"}}] [parents mother father])
[{:father "George", :mother "Alicia"} "Alicia" "George"]
(let [conns (atom (apply concat [nil] (repeat [:conn1 :conn2 :conn3]))) next-conn (fn [] (first (swap! conns next)))] [(next-conn) (next-conn) (next-conn)])
[:conn1 :conn2 :conn3]
(let [thunk #(throw (Exception. "OMG")) wrap-try (fn [f] (try (f) (catch Exception e "Caught it!")))] (wrap-try thunk))
"Caught it!"(defn toggler-factory [f1 f2] (let [a (atom true)] (fn [& args] (apply (if @a f1 f2) args) (swap! a not))))
#'user/toggler-factory
(let [data [[[1 2 3] [4 5 6]] [[7 8 9] [10 11 12]]]] (update-in data [1 0 2] inc))
[[[1 2 3] [4 5 6]] [[7 8 10] [10 11 12]]]
(let [a (sort-by #(< 1 (val %)) {:a 1, :b 2, :c 5, :d 0})] (pr a) (into {} a))
{:a 1, :b 2, :c 5, :d 0}
"([:a 1] [:d 0] [:b 2] [:c 5])"(let [list '(1 2 3 4 5)] (map (fn [first] (cons first (remove #(identical? first %) list))) list))
((1 2 3 4 5) (2 1 3 4 5) (3 1 2 4 5) (4 1 2 3 5) (5 1 2 3 4))
(let [vals->map (fn [f vals] (reduce (fn [m v] (assoc m v (f v))) {} vals))] (vals->map inc [1 2 3]))
{1 2, 2 3, 3 4}
(let [x (str "a" "b") y (str "a" "b")] [(identical? x y) (apply identical? (map #(.intern %) [x y]))])
[false true]
(let [map1 {:a 1, :b 2, :c 3} set1 #{:a :b}] (apply dissoc map1 (keys (apply dissoc map1 set1))))
{:a 1, :b 2}
(let [maps [{:a 1, :b 2} {:a 2, :b 2}]] (into {} (map (juxt identity (apply juxt maps)) (keys (first maps)))))
{:a [1 2], :b [2 2]}
(let [coll [{:i1 1, :i2 2} {:i1 3, :i2 4}]] (into {} (map (juxt identity (apply juxt coll)) (keys (first coll)))))
{:i1 [1 3], :i2 [2 4]}
(let [ls (lazy-seq (if (zero? (rand-int 2)) nil [1 2 3]))] [(if ls :yes :no) (if (seq ls) :yes :no)])
[:yes :no]
(defmacro let-map [m & body] `(let [{:keys ~(vec (map #(symbol (name %)) (keys m)))} ~m] (do ~@body)))
#'user/let-map
(let [[_ n] (drop-while #(not (#{:key} %)) [1 2 3 4 5 :key 1000 6 7 8])] n)
1000(let [pred #{4} coll (range 0 10 2)] (reduce #(if (pred %2) (reduced %1) (inc %1)) 0 coll))
2(defn compart [pred s] (let [[n1 n2] (split-with pred s)] (if (seq n2) (concat [n1] (compart pred (rest n2))) [n1])))
#'user/compart
(let [m {:foo 1, :bar 2} k (keys m) v (vals m)] [(zipmap k v) (zipmap v k)])
[{:bar 2, :foo 1} {1 :foo, 2 :bar}]
(let [func (fn [x] (+ x (* 3 (- (rand) (rand)))))] (map #(map func %) [[1 2] [3 4]]))
((0.16364878820258677 0.16778438158835707) (5.015038016321061 2.3942211524859474))
(defn foomap [fn lst] (if (empty? lst) lst (let [temp (map fn lst)] (cons (first temp) (foomap fn (rest temp))))))
#'user/foomap
(let [s "***" n 7 spaces (repeat (/ (- n (count s)) 2) \space)] (apply str (concat spaces s spaces)))
" *** "(let [Length 20 Pad \- Name (vec "TEttingerLivesInCaliforniaSoItIsGettingLate")] (apply str (map #(get Name %1 %2) (range) (repeat Length Pad))))
"TEttingerLivesInCali"(-> {: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}
(let [last-nth (fn [coll n] (nth coll (- (count coll) n 1)))] (= (last-nth (map inc (range 3)) 2) 1))
true(let [f #(fn [& y] (apply % (reverse y)))] ((f map) (replicate 10 (range 10)) ((f partial) inc map)))
((1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10) (1 2 3 4 5 6 7 8 9 10))
(let [s (apply str (map char (range 0 0xA0)))] (clojure.string/replace s #"\p{C}" #(format "\\\\x%02x" (int (first %)))))
"\\\\x00\\\\x01\\\\x02\\\\x03\\\\x04\\\\x05\\\\x06\\\\x07\\\\x08\\\\x09\\\\x0a\\\\x0b\\\\x0c\\\\x0d\\\\x0e\\\\x0f\\\\x10\\\\x11\\\\x12\\\\x13\\\\x14\\\\x15\\\\x16\\\\x17\\\\x18\\\\x19\\\\x1a\\\\x1b\\\\x1c\\\\x1d\\\\x1e\\\\x1f !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\\\\x7f\\\\x80\\\\x81\\\\x82\\\\x83\\\\x84\\\\x85\\\\x86\\\\x87\\\\x88\\\\x89\...
(let [t (transient {})] (doseq [i (range 20) j (range 20) k (range 20)] (assoc! t [j k] i)) (persistent! t))
{[0 0] 19, [0 1] 19, [0 2] 19, [0 3] 19, [0 4] 19, [0 5] 19, [0 6] 19, [0 7] 19}
(let [fixers [#(if (= 1 (:id %)) (assoc % :id 2) %)]] (reduce #(%2 %1) {:id 1} fixers))
{:id 2}
(let [a (fn b [x s] (if (pos? x) (b (dec x) (* x s)) s))] (a 5 1))
120(let [v [1 2 3] n 1 elem "a"] (into (subvec v 0 n) (list* elem (subvec v n))))
[1 "a" 2 3]
(let [a {:a 1, :b 0, :c 1}] (mapv first (filter #(= (apply max (vals a)) (second %)) a)))
[:a :c]
(let [name 'n parent '[a b c] fields '[d e f]] `(defrecord ~name ~(into parent fields)))
(clojure.core/defrecord n [a b c d e f])
(let [[a b c] [1 2 3] v [a b]] (println "v is " v ", c is " c))
nil"v is [1 2] , c is 3\n"(let [f #(do (pr %) %)] (map second (sort-by first (map (juxt f identity) ['5 4 3 2 1]))))
(1 2 3 4 5)
"54321"(let [list [0 1 2 3]] (map #(take 4 %) (take 4 (iterate #(drop 1 %) (cycle list)))))
((0 1 2 3) (1 2 3 0) (2 3 0 1) (3 0 1 2))
(let [funcs {:a inc, :b dec} values {:b 5, :a 10}] (into {} (for [[k f] funcs] [k (f (values k))])))
{:a 11, :b 4}

