((fn [& {:keys [a b]}] [":a" a ":b" b]) :a 1 :b 2)
[":a" 1 ":b" 2]
(reduce (fn [a x] (str a x)) "" [1 2 3 4 5])
"12345"
(apply str (map (fn [[a b]] (str "%" a b)) (partition 2 "0221caf96a")))
"%02%21%ca%f9%6a"
(sorted-map-by (fn [[a] [b]] (< a b)) [1 2] :foo [1 3] :bar)
{[1 2] :bar}
(defn key-comparer [key] (fn [a b] (compare (get a key) (get b key))))
#'user/key-comparer
(let [a [1 2 1 2 3] b [4 3 4 2 4 1 0]] [(map a b) (map b a)])
[(3 2 3 1 3 2 1) (3 4 3 4 2)]
(reductions (fn [[sum prev] [a b]] [(+ sum a b) [a b]]) [0 0] (map list (range 5) (range 5 10)))
([0 0] [5 [0 5]] [12 [1 6]] [21 [2 7]] [32 [3 8]] [45 [4 9]])
(into {} (for [[x y] '{a {p 1, q 2}, b {m 3, n 4}} [a b] y] [[a x] b]))
{[m b] 3, [n b] 4, [p a] 1, [q a] 2}
(let [a (into-array [1 2 3 4 5]) s (doall (seq a))] (println (first s) ".") (aset a 0 42) (println (first s) ".") (println (aget a 0) "."))
nil
"1 .\n42 .\n42 .\n"
(defmacro when-and-let [bnds & body] (loop [a (partition 2 bnds) b (cons 'do body)] (if (empty? a) b (recur (butlast a) (cons 'when-let (conj (list b) (vec (last a))))))))
#'user/when-and-let
(let [a [[1 23] [3 65]] b (map #(- (first %1) (first %2) 1) a (cons [0] a))] (mapcat #(concat (repeat %1 0) [(second %2)]) b a))
(23 0 65)
(take 10 ((fn fib ([] (cons 1 (fib 0 1))) ([a b] (cons (+ a b) (lazy-seq (fib b (+ a b))))))))
(1 1 2 3 5 8 13 21 34 55)
(defn swap-key [coll a b] (let [av (coll a) bv (coll b)] (-> coll (assoc a bv) (assoc b av))))
#'user/swap-key
(reduce (fn [[a v] k] [(get a k) (conj v k (get a k))]) [{:a {:b {:c 321}}} []] [:a :b :c])
[321 [:a {:b {:c 321}} :b {:c 321} :c 321]]
(let [a 23] (doseq [b (range 24)] (print (mod (+ (min (- a b) (- b a)) 24) 24) " ")))
nil
"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 0 "
(defn a [m n] (cond (= 0 m) (+ n 1) (= 0 n) (a (- m 1) 1) :else (a (- m 1) (a m (- n 1)))))
#'user/a
((defn fib [n] (letfn [(f [x a] (if (= x 2) a #(f (dec x) (conj a (apply +' (take-last 2 a))))))] (trampoline f n [0 1]))) 10)
[0 1 1 2 3 5 8 13 21 34]
(let [{:keys [a], :as m} {:a 42, :b 11}] [a (dissoc m :b)])
[42 {:a 42}]
(for [a [1 2 3] :let [b ((fn [] (prn "here") 1))]] (prn a))
(nil nil nil)
"\"here\"\n1\n\"here\"\n2\n\"here\"\n3\n"
(let [{:keys [a b], :as m} {:a 1, :b 2}] [a b m])
[1 2 {:a 1, :b 2}]
(reduce (fn [a b] (+ (a 1) (b 1))) {:a 1, :b 2})
3
(let [lalala 1] (defn foo [a b c] (println a b c lalala)))
#'user/foo
(letfn [(a [x] (inc (b x))) (b [y] (* 2 y))] (a 3))
7
(let [pow (fn [a b] (reduce * (repeat b a)))] (pow 2/7 3))
8/343
((fn f [a & [{:keys [b], :or {b 42}}]] (+ a b)) 1)
43
(defn combine-if [a b] (if-let [ab (remove nil? [a b])] (apply + ab)))
#'user/combine-if
(remove #(contains? '#{a b nil} %) '[a b c nil])
(c)
(mapcat (fn [[a b]] [a (- b)]) (partition 2 [1 2 3 4]))
(1 -2 3 -4)
(first (nth (iterate (fn [[a b]] [b (+ a b)]) [0 1]) 6))
8
((fn [[a b c]] (str a "-" b "-" c)) [:a :b :c])
":a-:b-:c"
((fn [a b & [more]] [a b more]) 1 2 3 4 5)
[1 2 3]
(for [[a b] (partition 2 1 [1 2 3 4])] (list b a))
((2 1) (3 2) (4 3))
(let [[a b c d] (seq (set (range 100000)))] [a b c d])
[0 60363 20083 25535]
(map-indexed #(assoc %2 :index %1) (let [b {} a {:s b}] [a b]))
({:index 0, :s {}} {:index 1})
(defn make-operator [x y] (let [myx x] (fn [a b] (myx a b))))
#'user/make-operator
(map (fn [a b] (+ a b)) [1 2 3] [10 100 1000])
(11 102 1003)
((fn [{:keys [a b]}] (+ a b)) {:a 22, :b 20, :c "OK"})
42
(let [twodvec [[1 2 3] [4 5 6] [7 8 9]]] (for [a twodvec b a] (+ b (apply max a))))
(4 5 6 10 11 12 16 17 18)
(let [foo [1 2 3]] (second (reduce (fn [[a x] b] [a (and x (= a b))]) [true (first foo)] (rest foo))))
false
(let [a [[1 23] [3 65]] b (map #(- (first %1) (first %2) 1) a (cons [-1] a))] (mapcat #(concat (repeat %1 0) [(second %2)]) b a))
(0 23 0 65)
(let [f (fn [& {:keys [a b c], :or {a 1, b 2, c 3}, :as params}] (println a b c))] (f))
nil
"1 2 3\n"
(reduce (fn [m [a b]] (let [item (m a [])] (assoc m a (conj item b)))) {} '[[foo bar] [foo zonk] [bar foo]])
{bar [foo], foo [bar zonk]}
(mapcat (fn [[p & s]] (map #(conj % p) s)) '((a (b c) (c b)) (b (a c) (c a))))
((a b c) (a c b) (b a c) (b c a))
(some #{'(e a)} (partition 2 (interleave '(a b c d e) (rest (cycle '(a b c d e))))))
(e a)
(let [foo [1 1 1]] (second (reduce (fn [[a x] b] [a (and x (= a b))]) [true (first foo)] (rest foo))))
false
(let [cpcount #(.codePointCount % 0 (.length %)) a "\ud80c" b "\udc00"] (map (juxt count cpcount) [a b (str a b)]))
([1 1] [1 1] [2 1])
((fn [{:keys [a b c d]}] [a b c d]) {:a 1, :c 8})
[1 nil 8 nil]
(defmacro foo [a] (let [bar (+ a 2)] `(fn [bar] (* bar 3))))
#'user/foo
((fnil (fn [a b c] [a b c]) 1 2 3) nil nil 5)
[1 2 5]
(let [f (fn [a] (+ a 5)) g (fnil f 10)] (g nil))
15