(->> (range 256) (filter #(or (<= 65 % 90) (<= 97 % 122))) (map char) (apply str))
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
((fn [& rest] (->> rest (apply map vector) (apply concat) (apply hash-map))) [:a :b :c] [1 2 3])
{:a 1, :b 2, :c 3}
(->> (filter odd? (map #(* % %) (iterate inc 1))) (take-while #(< % 10000000000)) (reduce +))
166666666650000
(->> [[:a :b] [:a :c] [:d :e]] (group-by first) (map (fn [[k v]] [k (map second v)])) (into {}))
{:a (:b :c), :d (:e)}
(let [data [[:a 1] [:a 2] [:b 3]]] (->> (for [[k v] data] {k [v]}) (apply merge-with concat)))
{:a (1 2), :b [3]}
(defmacro when-lets [pairs & body] `(let [~@pairs] (when (and ~@(->> pairs (partition 2) (map first))) ~@body)))
#'user/when-lets
(let [foo [1 2 3 4]] (->> (map #(= %1 (inc %2)) foo (rest foo)) (every? true?)))
false
(defn correct-answer-for [q] (->> q (reverse) (apply str) (read-string) (name) (reverse) (remove #{\?}) (apply str) (read-string)))
#'user/correct-answer-for
(take 20 (iterate #(->> % - (+ (-> % int (* 2))) inc (/ 1)) 1))
(1 1/2 2N 1/3 3/2 2/3 3N 1/4 4/3 3/5 5/2 2/5 5/3 3/4 4N 1/5 5/4 4/7 7/3 3/8)
((fn select-keys [m ks] (->> ks (map #(find m %)) (into {}))) {:x nil, :y 5} [:x])
{:x nil}
(letfn [(k [& xs] (->> (iterate (partial * 1000) 1) (map * (reverse xs)) (reduce +)))] (k 18 869 726 156))
18869726156
(->> ["command" "web" "port" "8080"] (partition 2) (map (fn [[a b]] [(keyword a) b])) (apply concat) (apply hash-map))
{:command "web", :port "8080"}
(let [f #(->> (vector %2) (cons %1) (flatten))] (= (f 1 2) (f 1 [2]) [1 2]))
true
(defmacro <<- [& body] (let [wraps (butlast body) body (last body)] `(->> (do ~@body) ~@(reverse wraps))))
#'user/<<-
(->> "make this into bigrams" (#(.split %1 "\\s+")) (partition 2 1) (map #(clojure.string/join " " %1)))
("make this" "this into" "into bigrams")
(->> [[:foo "bar"] [:baz "quux"] [:foo "doh"]] (group-by first) (map (fn [[k v]] [k (map last v)])) (into {}))
{:baz ("quux"), :foo ("bar" "doh")}
(#(->> % (group-by :key1) vals (map first)) [{:k2 "any val", :key1 "12345"} {:k1 "12345", :k2 "other val"}])
({:k2 "any val", :key1 "12345"} {:k1 "12345", :k2 "other val"})
(->> [{:id 1, :name "Chris"} {:id 3, :name "Jon"} {:id 5, :name "Tom"}] (filter #(= (:id %) 5)))
({:id 5, :name "Tom"})
(let [coll [:a :b :c :d :e]] (->> coll (iterate pop) (take (count coll)) (reverse) (cons []) (mapv vector coll)))
[[:a []] [:b [:a]] [:c [:a :b]] [:d [:a :b :c]] [:e [:a :b :c :d]]]
(let [m1 {:a 1, :b 2} m2 {:b 2, :c 3}] (->> (keys m1) (remove #(contains? m2 %))))
(:a)
(->> '((1 2 3) (4 5 6)) (map #(interpose \tab %)) (interpose \newline) flatten (apply str))
"1\t2\t3\n4\t5\t6"
(->> "9834258722394" (map #(new Integer (str %))) (partition 5 1) (map #(apply * %1)) (apply max))
2240
(defn rev-digits [n] (->> n (iterate #(quot % 10)) (take-while (complement zero?)) (map #(rem % 10))))
#'user/rev-digits
(->> (range (* x 10) (* (inc x) 10)) (partition 2) (map vec) (into {}) (for [x (range 10)]) (into {}))
{0 1, 2 3, 4 5, 6 7, 8 9, 10 11, 12 13, 14 15, 16 17, 18 19, 20 21, 22 23, 24 25, 26 27, 28 29, 30 31, 32 33, 34 35, 36 37, 38 39, 40 41, 42 43, 44 45, 46 47, 48 49, 50 51, 52 53, 54 55, 56 57, 58 59, 60 61, 62 63, 64 65, 66 67, 68 69, 70 71, 72 73, 74 75, 76 77, 78 79, 80 81, 82 83, 84 85, 86 87, 88 89, 90 91, 92 93, 94 95, 96 97, 98 99}
(->> [[:foo "bar"] [:baz "quux"] [:foo "doh"]] (group-by first) (map (fn [[k v]] [k (vec (map last v))])) (into {}))
{:baz ["quux"], :foo ["bar" "doh"]}
(letfn [(f ([a b] (f a b 3)) ([a b c] (+ a b c)))] (->> 10 (f 1)))
14
(letfn [(pile [n cards] (->> (range n) (mapcat #(take-nth n (drop % cards))) reverse))] (pile 3 (range 10)))
(8 5 2 7 4 1 9 6 3 0)
(let [f (fn [n m] (conj (->> n range (take-nth (int (/ n m))) vec) n))] (f 100 3))
[0 33 66 99 100]
(let [delim "^"] (clojure.string/split "hello^world" (re-pattern (str "[" (->> delim first int (format "%04x") (str "\\u")) "]"))))
["hello" "world"]
(->> (ns-map *ns*) (map second) (filter #(= (-> % meta :ns str) "somnium.congomongo")) (map #(ns-unmap *ns* %)))
()
(->> " 1:2 2:3 " .trim (re-seq #"(?:\s+|(\d+):(\d+))") (take-nth 2) (map (comp vec rest)) (into {}))
{"1" "2", "2" "3"}
(letfn [(char-set [c] (->> c (map char) set))] (= (char-set "does not use the whole alphabet") (char-set (range 97 123))))
false
(->> "this is a test" (#(clojure.string/split % #" ")) (map reverse) (map #(apply str %)) (clojure.string/join " "))
"siht si a tset"
((fn select-keys [m ks] (->> ks (map #(find m %)) (filter identity) (into {}))) {:x nil, :y 5} [:x])
{:x nil}
(defn get-name [] (->> 'clojure.core ns-publics keys (mapcat (fn [s] (clojure.string/split (name s) #"-"))) shuffle (take 3) (clojure.string/join \-) symbol))
#'user/get-name
(letfn [(!-?> [&$ &!] (if (> &! 1) (!-?> (->> &$ (* &!)) (-> &! dec)) &$))] (!-?> 1 5))
120
(->> (ns-map *ns*) (map second) (filter #(= (-> % meta :ns str) "somnium.congomongo")) (map #(ns-unmap *ns* (.sym %))))
()
(letfn [(pile [n cards] (->> (range n) (mapcat #(take-nth n (drop % cards))) (reduce conj nil)))] (pile 3 (range 10)))
(8 5 2 7 4 1 9 6 3 0)
(defn latest-tile [grid x y] (->> grid (filter #(and (= (:x %) x) (= (:y %) y))) (sort-by :time) (last)))
#'user/latest-tile
(->> (range 20) (shuffle) (partition 3 1) (filter (fn [[a b c]] (and (< b a) (< b c)))) (first))
(10 2 11)
(->> "this is a test" (#(clojure.string/split % #" ")) (map (comp #(apply str %) reverse)) (clojure.string/join " "))
"siht si a tset"
(letfn [(pile [n cards] (->> (range n) (map #(take-nth n (drop % cards))) (apply concat)))] (pile 3 (range 10)))
(0 3 6 9 1 4 7 2 5 8)
(->> (all-ns) (mapcat (comp keys ns-publics)) (map name) (filter #(.startsWith % "def")) (remove #(.startsWith % "default")) (clojure.string/join " "))
"defmethod defonce defn- defprotocol defmulti defrecord"
(map #(->> % ((apply juxt [:a :b])) (clojure.string/join ",") (format "[%s]")) [{:a 1, :b 2} {:a 5, :b 7}])
("[1,2]" "[5,7]")
(defmacro list+ [& forms] (->> forms (map (fn [x] (if (and (symbol? x) (not (contains? &env x))) (str x) x))) (cons `list)))
#'user/list+
(let [m1 {:foo 1, :bar 2, :baz 3} m2 {:foo 4, :bar 5}] (->> (keys m1) (map (juxt identity m2)) (into {})))
{:bar 5, :baz nil, :foo 4}
(->> [\A \Z \a \z \0 \9] (map int) (partition 2) (map (fn [[l h]] (range l h))) (apply concat) (map char))
(\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 \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 \0 \1 \2 \3 \4 \5 \6 \7 \8)
(->> [1 2 3 2 1] (reductions (fn [[_ coll] part] (split-at part coll)) [nil (range 10)]) next (map first) (take-while identity))
((0) (1 2) (3 4 5) (6 7) (8))
(defn get-name [] (->> 'clojure.core ns-publics keys (mapcat (fn [s] (clojure.string/split (name s) #"-"))) shuffle (take (+ 2 (rand-int 3))) (clojure.string/join \-) symbol))
#'user/get-name
(->> '((0 1 2) (3 4 5) (6 7 8) (9 10 11)) (group-by #(even? (first %))) vals (map flatten))
((0 1 2 6 7 8) (3 4 5 9 10 11))