((comp (partial apply hash-map) (juxt (constantly :a) :a (constantly :inner_a) (comp :inner_a :user))) {:a 2, :b 3, :user {:inner_a 5, :inner_b 9}})
{:a 2, :inner_a 5}
(reduce-kv (fn [a k v] (assoc a k (first v))) {} {:foo [{:bar :baz}], :bar [{:baz :bop}]})
{:bar {:baz :bop}, :foo {:bar :baz}}
(for [[k v] {:foo "jams", 12 15}] (str "I have a " k " and a " v))
("I have a :foo and a jams" "I have a 12 and a 15")
(let [m {:a 0}] (cond-> m (contains? m :a) (assoc :a :foo) (contains? m :b) (assoc :b :bar)))
{:a :foo}
(for [[a b c] (map vector (range) [:foo :bar :baz] "hahaha foo")] {:a a, :b b, :see c})
({:a 0, :b :foo, :see \h} {:a 1, :b :bar, :see \a} {:a 2, :b :baz, :see \h})
(map (juxt seq? sequential?) [[1 2 3] {:a 1, :b 2} '(1 2 3) (seq [1 2 3]) (lazy-seq [1 2 3])])
([false true] [false false] [true true] [true true] [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 [x {:foo 1, :bar 2}] (conj x {:bar (or (:bar x) 3), :baz (or (:baz x) 4)}))
{:bar 2, :baz 4, :foo 1}
(let [m {:foo '[bar baz], :quz '[etc]}] (doseq [[k v] m] (apply println "!!" k v)))
nil"!! :foo bar baz\n!! :quz etc\n"(defn -:> [v & pairs] (let [pairs (partition 2 pairs) keys (map first pairs) fns (map second pairs)] (zipmap keys ((apply juxt fns) v))))
#'user/-:>
(with-local-vars [a 0 b 1] (dotimes [_ 10] (var-set a (+ @a @b)) (var-set b (+ @a @b))) (mapv (juxt identity deref) [a b]))
[[#'G__1243627 6765] [#'G__1243628 10946]]
(map (comp (partial apply hash-map) (juxt key (comp :c val))) {:one {:a 1, :b 2, :c 3}, :two {:a 10, :b 20, :c 30}})
({:one 3} {:two 30})
(let [g (->> (gensym) str (re-find #"\d+") (#(Integer/parseInt %)) inc inc inc (str "G__") symbol)] ((juxt identity eval) `(let [~g (gensym)] ~g)))
[(clojure.core/let [G__1218876 (clojure.core/gensym)] G__1218876) G__1218876]
(let [stack [1 2] pop-peek (juxt pop peek) [stack arg1] (pop-peek stack) [stack arg2] (pop-peek stack)] (conj stack (+ arg1 arg2)))
[3]
(let [list [:foo :bar "baz" :quux :yay] [a [b & c]] (split-with (complement string?) list)] [a b c])
[(:foo :bar) "baz" (:quux :yay)]
(hash-map [1 2 3] "a" :foo 2 "3" 6 8 9 \a 2 '(1 4 3) 6 'a 'b)
{(1 4 3) 6, "3" 6, 8 9, :foo 2, [1 2 3] "a", \a 2, a b}
(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}]
(into {} (map (fn [[k i]] (vector k (nth (object-array '[a b c]) i))) (partition 2 [:foo 0 :bar 2])))
{:bar c, :foo a}
(let [[positional kwargs] (split-with (complement keyword?) [1 2 3 :foo 4 :bar 5]) arg-map (apply hash-map kwargs)] [positional arg-map])
[(1 2 3) {:bar 5, :foo 4}]
((fn [name doc-string & [foo bar :as coll]] {:name name, :doc-string doc-string, :foo foo, :bar bar}) 'a 'b 'c 'd)
{:bar d, :doc-string b, :foo c, :name a}
(apply merge-with into (for [[k v] {:foo #{1 2}, :bar #{3 4}} v v] {v #{k}}))
{1 #{:foo}, 2 #{:foo}, 3 #{:bar}, 4 #{:bar}}
(update-in {:a [0 1 2 3], :b [4 5 6 7]} [:a] (fn [x] (map (fn [_] :foo) x)))
{:a (:foo :foo :foo :foo), :b [4 5 6 7]}
(let [m {:a nil, :b :foo}] (reduce #(dissoc % %2) m (filter #(nil? (m %)) (keys m))))
{:b :foo}
(defn -:> [v & pairs] (let [pairs (partition 2 pairs) keys (map first pairs) fns (map second pairs)] (zipmap ((apply juxt fns) v) keys)))
#'user/-:>
(let [v [1 5 3 3 2 4 5 5 4 5 1 2 1 2 3 5]] (map (juxt first count) (partition-by identity v)))
([1 1] [5 1] [3 2] [2 1] [4 1] [5 2] [4 1] [5 1] [1 1] [2 1] [1 1] [2 1] [3 1] [5 1])
(sort-by (juxt :otherkey (comp count :key)) (comp - compare) [{:key '(1 2 3 4), :otherkey 10} {:key '(1 2 3), :otherkey 12}])
({:key (1 2 3), :otherkey 12} {:key (1 2 3 4), :otherkey 10})
(reductions (fn [[k1 v1] [k2 v2]] [k2 (+ v1 v2)]) [[:foo 1] [:bar 2] [:baz 3] [:qux 4] [:noop 5]])
([:foo 1] [:bar 3] [:baz 6] [:qux 10] [:noop 15])
(let [m {:foo 0, :bar 2} v '[a b c]] (into {} (map #(vector % (v (m %))) (keys m))))
{:bar c, :foo a}
(array-map [1 2 3] "a" :foo 2 "3" 6 8 9 \a 2 '(1 4 3) 6 'a 'b)
{(1 4 3) 6, "3" 6, 8 9, :foo 2, [1 2 3] "a", \a 2, a b}
((juxt #(apply concat (take-nth 2 %)) #(apply concat (take-nth 2 (next %)))) (partition-by odd? [1 2 2 3 4 5 5 7 8 9]))
[(1 3 5 5 7 9) (2 2 4 8)]
((juxt (partial take 3) (comp (partial take 1) (partial drop 3)) (comp (partial take 2) (partial drop 4))) (re-seq #"\w+" "blah blah blah blah blah blah"))
[("blah" "blah" "blah") ("blah") ("blah" "blah")]
(let [f #(if (= % 7) [:hi 6 6] :hi) g inc h inc] (= ((comp f g h) 5) ((juxt f g h) 5)))
true(get (apply merge-with into (for [[k v] {:foo #{1 2}, :bar #{3 4}} v v] {v #{k}})) 4)
#{:bar}
(let [v (with-meta [1 2] {:foo :bar})] (map #(meta %) [v (conj v 3) (map identity v) (subvec v 1)]))
({:foo :bar} {:foo :bar} nil nil)
(->> rand repeatedly (partition 4) (take 20) (map (juxt identity #(apply hash-map %))) (map #(map (comp flatten seq) %)) (map #(apply = %)) set)
#{false true}
((juxt #(reduce concat (take-nth 2 %)) #(reduce concat (take-nth 2 (next %)))) (partition-by odd? [1 2 2 3 4 5 5 7 8 9]))
[(1 3 5 5 7 9) (2 2 4 8)]
(let [v [1 5 3 3 2 4 5 5 4 5 1 2 1 2 3 5]] (map (juxt first count) (vals (group-by identity v))))
([1 3] [5 5] [3 3] [2 3] [4 2])
(let [m {:a 0, :b 1, :c 2}] (cond-> m (contains? m :a) (assoc :a :foo) (contains? m :b) (assoc :b :bar)))
{:a :foo, :b :bar, :c 2}
(let [x [{:id 1, :foo :bar} {:id 3, 1 "hello", 2 "hi"}]] (into {} (map #(vector (% :id) (dissoc % :id)) x)))
{1 {:foo :bar}, 3 {1 "hello", 2 "hi"}}
(let [m {:apple {:type :foo}, :orange {:type :bar}} [apple-type orange-type] (map #(get-in m %) [[:apple :type] [:orange :type]])] [apple-type orange-type])
[:foo :bar]
(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 [m '{:Foo #{:Bar :Baz}, :Flib #{:Bar :Box}}] (apply merge-with into {} (for [[k vs] m v vs] {v #{k}})))
{:Bar #{:Flib :Foo}, :Baz #{:Foo}, :Box #{:Flib}}
(let [test-kwargs (fn [x y & args] (let [kwargs (apply hash-map args)] (println x y kwargs)))] (test-kwargs "one" "two" :foo true :bar false :baz []))
nil"one two {:baz [], :bar false, :foo true}\n"(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(into {} (map (juxt first #(let [lvals (rest %1)] (if (= (count lvals) 1) (first lvals) (vec lvals)))) [[:a 1 2 3] [:b 4 5 6] [:c 7]]))
{:a [1 2 3], :b [4 5 6], :c 7}
((comp (juxt :accum :result) reduce) (fn [{:keys [accum result]} x] {:accum (conj accum x), :result (conj result (accum x))}) {:accum #{}, :result []} [:a :b :b :c :d :c])
[#{:a :b :c :d} [nil nil :b nil nil :c]]
(reduce (fn [m [k v]] (update-in m [k] (fnil conj #{}) v)) {15 #{5 10}, 25 #{5}} (map (juxt #(+ 5 %) identity) #{10 20 30}))
{15 #{5 10}, 25 #{5 20}, 35 #{30}}
(let [m1 {:foo 1, :bar 2, :baz 3} m2 {1 4, 2 5}] (reduce-kv (fn [acc k v] (assoc acc k (m2 v))) {} m1))
{:bar 5, :baz nil, :foo 4}
((fn [m keypaths] (into {} (for [[k path] keypaths] [k (get-in m path)]))) {:a 2, :b {:c 3}, :foo 1} {:x [:a], :y [:b :c]})
{:x 2, :y 3}
((fn transform [m & args] (reduce (fn [m [k-vec v]] (assoc-in m k-vec v)) m (partition 2 args))) {:quux 3} [:foo] 1 [:bar :baz] 2)
{:bar {:baz 2}, :foo 1, :quux 3}

