(let [a (atom []) res (partition-by #(do (swap! a conj %) (zero? (mod % 5))) (iterate inc 0)) forced (doall (take 3 res))] [forced @a])
[((0) (1 2 3 4) (5)) [0 1 1 2 3 4 5 5]]
(->> ["7" "7 elements" "7 elements landing" "7 elements landing page" "add"] (partition 2 1 nil) (remove (fn [[a b]] (and b (.contains b a)))) (map first))
("7 elements landing page" "add")
(group-by #(cond (.startsWith % "//TODO: ") :special (.startsWith % "//") :comment :true :data) ["//this is a comment line" "01-this is a data line" "//TODO: todo line"])
{:comment ["//this is a comment line"], :data ["01-this is a data line"], :special ["//TODO: todo line"]}
(let [yield (fn [seq] (let [a (atom (cons nil seq))] (fn [] (first (swap! a next))))) test (yield (cycle [:conn1 :conn2 :conn3 :conn4]))] (for [_ (range 10)] (test)))
(:conn1 :conn2 :conn3 :conn4 :conn1 :conn2 :conn3 :conn4 :conn1 :conn2)
(reduce-kv (fn [m k v] (let [[_ a b] (re-matches #"([a-z]*)([0-9]*)" k)] (assoc-in m [a b] v))) {} {"abc12" :a, "abc13" :b, "abd42" :c})
{"abc" {"12" :a, "13" :b}, "abd" {"42" :c}}
((fn [a b] (let [s->v (fn [vs] (vec (reverse (drop-while zero? (reverse (map #(Integer. %) (.split vs "[.]")))))))] (compare (s->v a) (s->v b)))) "0.1.3" "0.1.3.0")
0
(let [a (atom 10) old-value (atom nil) instrumented-inc ((fn [f] (fn [x & args] (reset! old-value x) (apply f x args))) inc)] [(swap! a instrumented-inc) @old-value])
[11 10]
(do (def h2 {"a" 1, "b" 2}) (let [{:keys [a b]} h2] b))
nil
(str "I'd like an " (clojure.string/join " and a " ["apple" "pear" "banana"]))
"I'd like an apple and a pear and a banana"
(map #(get '[a b c d e] %) [0 2 4])
(a c e)
(let* [map__2197 nil a (clojure.core/get map__2197 :a 1) b (clojure.core/get map__2197 :b 2)])
nil
(format ":foo is a :bar / :qux" {:foo 1, :bar 2, :qux 3})
":foo is a :bar / :qux"
(for [l '[a b c] n [1 2 3]] (str l n))
("a1" "a2" "a3" "b1" "b2" "b3" "c1" "c2" "c3")
(for [e '{a 1, b 2, c 3} x e] x)
(a 1 b 2 c 3)
(println (.replaceAll "Add a backslash in between teh spaces" " " "\\\\ "))
nil
"Add\\ a\\ backslash\\ in\\ between\\ teh\\ spaces\n"
(defn tester [#^longs x] (loop [a (long 0)] (recur (aget x 1 1))))
#'user/tester
(list* (map vector [1 2 3] '(a b c) '(4 5)))
([1 a 4] [2 b 5])
(defn area [r] "Computes area of a rectagle." (* (.width r) (.height r)))
#'user/area
(let [x '(a b c)] `(foo ~'x bar ~@x baz ~x))
(user/foo x user/bar a b c user/baz (a b c))
(def f (fn [[a b :as p1] [c d :as p2]] [p1 p2]))
#'user/f
(get "/hello/:a/:b/:c" "Hello to #{a} and #{b} and #{c}")
nil
(reduce (fn [a b] (if (= b 3) (reduced 3) b)) (range 6))
3
(reduce #(do %2 (inc %)) 0 '[a b c d e])
5
(let [a (map #(println "processing " %) [1 2 3 4])] 'something)
something
(defn a [n] (mapcat #(range 1 %) (range 1 (+ 2 n))))
#'user/a
(defn my-handler [{:keys [url body]}] (println url "has a count of" (count body)))
#'user/my-handler
(reduce (fn [a b] (if (= b 3) (reduced 3)) b) (range 6))
5
(let [[n [d]] '(a '(b c d))] {:n n, :d d})
{:d quote, :n a}
(clojure.string/replace "${a}.${b}.${c}" #"\$\{(.*?)\}" "$1")
"a.b.c"
(into {} (map #(vector % (str % "_val")) '(a b c d)))
{a "a_val", b "b_val", c "c_val", d "d_val"}
(let [L (with-meta (seq '(a b)) {:foo :bar})] (meta (conj L 'c)))
{:foo :bar}
(defmacro foo [] (let [a + b 1 c 2] `(~a ~b ~c)))
#'user/foo
(loop [a 1] (case a 1 (recur 3) 3 (recur 2) 4))
4
(clojure.string/replace "this is a test" #"[^ ]+" #(apply str (reverse %)))
"siht si a tset"
(clojure.string/replace "${a}.${b}.${c}" #"\$\{(.*)\}" "$1")
"a}.${b}.${c"
((resolve (symbol (apply str '[e v a l]))) '(+ 1 1))
(+ 1 1)
((fn [{:keys [a b c], :or {c 3}}] c) {:a 1, :b 2})
3
(def a [(vec (for [x (range 3) y (range 2)] [x y 0]))])
#'user/a
(apply (fn [a b] (a b)) ((apply juxt (map (fn [length] (comp second #(nth % length))) [27 15])) (filter (comp #{\?} last name first) (seq (ns-map *ns*)))))
false
(let [start {"name" "databases", "columns" ["name" "id"], "values" [["testdb" 1] ["mydb" 2]]}] (map (fn [vcoll] (into {} (mapcat (fn [a b] {(keyword a) b}) (start "columns") vcoll))) (start "values")))
({:id 1, :name "testdb"} {:id 2, :name "mydb"})
(let [sums (reductions + [1 2 3 4 5 6 7 8 9 4]) total (last sums)] (->> (partition 2 1 sums) (map (fn [[a b]] [a b total]))))
([1 3 49] [3 6 49] [6 10 49] [10 15 49] [15 21 49] [21 28 49] [28 36 49] [36 45 49] [45 49 49])
(let [filter-first (fn [pred s] (let [[a b] (split-with (comp not pred) s)] (concat a (rest b))))] (filter-first #(= 1 %) '(9 6 1 3 1)))
(9 6 3 1)
(let [start {"name" "databases", "columns" ["name" "id"], "values" [["testdb" 1] ["mydb" 2]]}] (mapcat (fn [vcoll] (map (fn [a b] {(keyword a) b}) (start "columns") vcoll)) (start "values")))
({:name "testdb"} {:id 1} {:name "mydb"} {:id 2})
(let [{{:keys [id], :as session} :session, {:strs [a b], :as params} :params} {:session {:id 0}, :params {"a" 1, "b" 2}}] [id a b session params])
[0 1 2 {:id 0} {"a" 1, "b" 2}]
(apply (fn [a b] (a b)) ((apply juxt (map (fn [length] (comp second #(nth % length))) [27 15])) (filter (comp #{\?} last name first) (seq (ns-map *ns*)))))
false
(defn foo "I don't do a whole lot." [x] (println x "Hello, World!"))
#'user/foo
(remove #{true} '(a b true c true d e f true))
(a b c d e f)
(defmacro mapify [& args] (zipmap (map (fn [a] `(quote ~a)) args) args))
#'user/mapify
(defn resume-shrink [resume job] "removes all unverifiable or irrelevant entries from a resume")
#'user/resume-shrink
(reduce (fn [count _] (inc count)) 0 '[a b c d e])
5