(defn in-out-with-both [in out both] (let [in (set in)] (for [b both] [(if (in b) :in :out) b])))
#'user/in-out-with-both
(clojure.string/join " " (let [coll [1 2 3 [10 20] 4]] (flatten (map #(vector % %) coll))))
"1 1 2 2 3 3 10 20 10 20 4 4"(let [f (fn [a b c] [c b a])] [(f 1 2 3) (apply f 1 [2 3])])
[[3 2 1] [3 2 1]]
(let [v [0 1 2 3] i 2] (apply conj (subvec v 0 i) (nthnext v (inc i))))
[0 1 3]
(let [maps [{:a 1, :b 2} {:x 5, :y 6}] [{:keys [a b]}] maps] [a b])
[1 2]
(defmacro def-csv-importer2 [table-name] (let [args (deref (resolve (symbol (str table-name "-fields"))))] (list* `defstruct (symbol (str table-name "-struct")) args)))
#'user/def-csv-importer2
(let [last-nth (fn [coll n] (nth coll (- (count coll) n)))] (= (last-nth [1 2 3] 2) 1))
false(let [x {:foo 1, :bar 2}] (conj x {:bar (or (:bar x) 3), :baz (or (:baz x) 4)}))
{:bar 2, :baz 4, :foo 1}
(let [id1 {:id 1} id2 {:id 2}] (= (set '({:id 1} {:id 2})) (set (list id1 id2))))
true(let [a [1 2 3] z (map long a) [_ ^:long b] z] (= b 2))
true(str "[" (let [out-er *out*] (with-out-str (print "before") (binding [*out* out-er] (print "while")) (print "after"))) "]")
"[beforeafter]""while"(let [x '({:_id "blah", :old_id 375} {:_id "hello", :old_id 376})] (zipmap (map :old_id x) (map :_id x)))
{375 "blah", 376 "hello"}
(take 10 (let [p (promise) s (lazy-cat [1 0] @p)] (deliver p (map + s (rest s))) @p))
(1 1 2 3 5 8 13 21 34 55)
(defn character-seq [reader] (lazy-seq (let [value (.read reader)] (if (= value -1) nil (cons (char val) (character-seq reader))))))
#'user/character-seq
(let [[foo & {:strs [name age]}] ["hi" "name" "tom" "age" "22"]] (format "Hello %s, age %s." name age))
"Hello tom, age 22."((let [c (map (comp resolve symbol) (.split "comp - inc" " "))] (apply (first c) (rest c))) 8)
-9(def in-a-rows (let [idx (partition 3 (range 9))] idx (map list idx) [[0 4 8] [2 4 6]]))
#'user/in-a-rows
(let [things ["ruby" "clojure" "java" "erlang" "python" "brainfuck"]] (format "Let's implement %s in %s!" (rand-nth things) (rand-nth things)))
"Let's implement clojure in clojure!"(take 200 (let [all ["a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z" "0" "1" "2" "3" "4" "5" "6" "7" "8" "9"]] (nth (iterate #(for [base % more all] (str base more)) all) 7)))
("aaaaaaaa" "aaaaaaab" "aaaaaaac" "aaaaaaad" "aaaaaaae" "aaaaaaaf" "aaaaaaag" "aaaaaaah" "aaaaaaai" "aaaaaaaj" "aaaaaaak" "aaaaaaal" "aaaaaaam" "aaaaaaan" "aaaaaaao" "aaaaaaap" "aaaaaaaq" "aaaaaaar" "aaaaaaas" "aaaaaaat" "aaaaaaau" "aaaaaaav" "aaaaaaaw" "aaaaaaax" "aaaaaaay" "aaaaaaaz" "aaaaaaa0" "aaaaaaa1" "aaaaaaa2" "aaaaaaa3" "aaaaaaa4" "aaaaaaa5" "aaaaaaa6" "aaaaaaa7" "aaaaaaa8" "aaaaaaa9" "aa...
(defn foo [f x] (fn [& args] (let [res (apply f args)] (if (= x res) nil res))))
#'user/foo
(let [id1 {:id 1} id2 {:id 2}] (filter #{id1 id2} #{{:id 1} {:id 2} {:id 3}}))
({:id 2} {:id 1})
(let [m [{:k1 [{:k2 42}]} {:k1 [{:k2 77}]}]] (map #(update % :k1 (fn [_] [{:k2 :meow}])) m))
({:k1 [{:k2 :meow}]} {:k1 [{:k2 :meow}]})
(clojure.string/join " " (let [coll [1 2 3 [10 20] 4]] (map #(vector % %) (flatten coll))))
"[1 1] [2 2] [3 3] [10 10] [20 20] [4 4]"(let [{:keys [a b], d :c, :as e} {:a 1, :b 2, :c 3}] [a b d e])
[1 2 3 {:a 1, :b 2, :c 3}]
(let [my-map {:a 1, :b 2, :not-found "kittens"} my-map-with-default #(my-map % (my-map :not-found))] [(my-map-with-default :a) (my-map-with-default :z)])
[1 "kittens"]
(let [{:keys [a b c], :as point} (merge {:a 0, :b 1} {:a 3})] [[a b c] point])
[[3 1 nil] {:a 3, :b 1}]
(let [oinc (fn [n] (reduce + n (map #(%) (repeat 2r000001000 #(*)))))] [(oinc 8) (oinc 32)])
[16 40]
(let [ms [{:a 1, :b 2} {:c 3}]] (-> ms pop (conj (-> ms peek (merge {:d 4})))))
[{:a 1, :b 2} {:c 3, :d 4}]
(let [x [1 2 3]] (map (fn [n _] (concat (drop n x) (take n x))) (range) x))
((1 2 3) (2 3 1) (3 1 2))
(let [x (atom {:a 10, :b [20 30]})] [(identical? x (swap! x identity)) (identical? @x (swap! x identity))])
[false true]
(let [m (hash-map :a 1 :b 2) f (juxt type identity)] (f (into (empty m) (map identity m))))
[clojure.lang.PersistentHashMap {:a 1, :b 2}]
(let [x {"one" 1, "two" 2, "three" 3} {:strs [one two three]} x] ['counting one two three])
[counting 1 2 3]
(let [anagram? (fn [a b] (= (frequencies a) (frequencies b)))] (map anagram? ["fred" "meat" "what"] ["derp" "team" "thaw"]))
(false true true)
(let [[[k0 v0] [k1 v1]] (map (fn [x] x) {:foo 1, :bar 2})] (print k0 v0 k1 v1))
nil":foo 1 :bar 2"(let [f (partial * 2)] (map #(%1 %2) (cycle [f identity]) [1 2 3 4 5 6]))
(2 2 6 4 10 6)
(let [foo (fn [] (println "foo")) bar (fn [] (println "bar")) fly {:foo foo, :bar bar}] ((fly :foo)))
nil"foo\n"(let [a (quote (foo (baz 1) (bar 2))) [b c d :as s] a] [a b c d])
[(foo (baz 1) (bar 2)) foo (baz 1) (bar 2)]
(let [v [1 2 3 4 5 6] split-list (split-at 3 v)] (concat (split-list 0) (next (split-list 1))))
(1 2 3 5 6)
(let [val "foo"] (cond (= val "bar") "it was bar" (= val "foo") "it was foo" :else nil))
"it was foo"(let [v [1 2 3 4 5 6] split-list (split-at 3 v)] (concat (first split-list) (next (second split-list))))
(1 2 3 5 6)
(let [my-map {:a 42, :b (zipmap (range 5) (range 5))} {:keys [a b]} my-map] (prn a b))
nil"42 {0 0, 1 1, 2 2, 3 3, 4 4}\n"(let [m {:a (delay (do (println "Doing") (* 2 2)))}] (println "Before") (println @(m :a)) (println "After"))
nil"Before\nDoing\n4\nAfter\n"(let [f (fn lz-rec-step [s] (lazy-seq (if (seq s) (cons (first s) (lz-rec-step (rest s))) [])))] (f (range 10)))
(0 1 2 3 4 5 6 7 8 9)
(let [[a b c] (re-matches #"([-+]?[0-9]+)/([0-9]+)" "22/7")] [a b c])
["22/7" "22" "7"]
(let [x (atom {:a 10, :b [20 30]})] [(= x (swap! x identity)) (= @x (swap! x identity))])
[false true]
(let [[k & ks :as keys] '[a b c d e]] {:k k, :ks ks, :keys keys})
{:k a, :keys [a b c d e], :ks (b c d e)}
(let [{:keys [a b c d]} {:a 1, :b 2, :c 3, :d 4}] [a b c d])
[1 2 3 4]
(let [orig (repeatedly 6 #(rand-int 4000)) m (reduce max orig)] [orig (split-with (partial not= m) orig)])
[(990 1536 2427 2651 1110 109) [(990 1536 2427) (2651 1110 109)]]
(let [f #(->> (vector %2) (cons %1) (flatten))] (= (f 1 2) (f 1 [2]) [1 2]))
true((fn [s] (let [[h & t] s] (do (print (type t)) (conj t h)))) '(1 2 3))
(1 2 3)
"clojure.lang.PersistentList"

