(let [ops (juxt + - *)] (take 10 (map ops (range) (range 20 10 -2))))
([20 -20 0] [19 -17 18] [18 -14 32] [17 -11 42] [16 -8 48])
((juxt (partial filter identity) (partial keep identity)) [0 1 nil false true 2 nil false])
[(0 1 true 2) (0 1 false true 2 false)]
(let [f (partial * 2)] (mapcat (juxt identity f) [1 2 3 4 5 6]))
(1 2 2 4 3 6 4 8 5 10 6 12)
((apply juxt (map (fn [idx] (fn [v] (get v idx))) [1 2])) [1 3 5])
[3 5]
(let [m ["the" "quick" "brown" "fox"]] ((juxt (partial apply max-key count) (partial min-key count)) m))
["brown" ["the" "quick" "brown" "fox"]]
((comp (partial apply map max) (juxt identity rest)) [1 5 4 3 2 6 7])
(5 5 4 3 6 7)
((comp first (partial apply drop) (juxt second first) vector) [:a :b :c :d :e] 3)
:d
(defn zagzig [n] (take n (apply mapcat list ((juxt reverse identity) (range 1 (inc n))))))
#'user/zagzig
((juxt #(seq (.split % " ")) #(seq (.split % " +"))) "a b")
[("a" "" "" "b") ("a" "b")]
((apply juxt (map (partial comp set) [filter remove])) odd? #{1 2 3 4 5})
[#{1 3 5} #{2 4}]
(for [n (range 20)] [n (class (reduce conj (array-map) (map (juxt identity identity) (range n))))])
([0 clojure.lang.PersistentArrayMap] [1 clojure.lang.PersistentArrayMap] [2 clojure.lang.PersistentArrayMap] [3 clojure.lang.PersistentArrayMap] [4 clojure.lang.PersistentArrayMap] [5 clojure.lang.PersistentArrayMap] [6 clojure.lang.PersistentArrayMap] [7 clojure.lang.PersistentArrayMap] [8 clojure.lang.PersistentArrayMap] [9 clojure.lang.PersistentHashMap] [10 clojure.lang.PersistentHashMap] [11 ...
(map #([`#{~%}] (+)) ((juxt filter remove) odd? #{1 2 3 4 5}))
(#{(1 3 5)} #{(4 2)})
(map #([`#{~@%}] (+)) ((juxt filter remove) odd? #{1 2 3 4 5}))
(#{1 3 5} #{2 4})
(map #(zipmap [:name :hp] ((juxt first second) %)) [["foo" 20] ["moo" 30] ["boo" 20]])
({:hp 20, :name "foo"} {:hp 30, :name "moo"} {:hp 20, :name "boo"})
((comp first (partial apply drop) (juxt second first) vector) [:a :b :c :P :e] 3)
:P
(->> [1 true false nil] (map (juxt (comp not not) boolean)) (every? (partial apply =)))
true
(map (juxt identical? = ==) [3 3000 3000 3000] [3 (+ 1000 2000) 3000 3000.0])
([true true true] [false true true] [false true true] [false false true])
((juxt (comp count filter) (comp count remove)) (comp #{"1.3"} :added) (map meta (vals (ns-publics 'clojure.core))))
[0 538]
(defn zigzag [n] (take n (flatten (apply map vector ((juxt reverse identity) (range 1 (inc n)))))))
#'user/zigzag
(let [append-to-self (comp (partial apply conj) (juxt (fnil identity []) identity))] (map append-to-self [[] [1] [2 3] nil]))
([[]] [1 [1]] [2 3 [2 3]] [nil])
(for [n (range 14 18)] [n (class (reduce conj (array-map) (map (juxt identity identity) (range n))))])
([14 clojure.lang.PersistentHashMap] [15 clojure.lang.PersistentHashMap] [16 clojure.lang.PersistentHashMap] [17 clojure.lang.PersistentHashMap])
((juxt (partial take-nth 2) (comp (partial take-nth 2) rest)) [1 2 3 4 5 6])
[(1 3 5) (2 4 6)]
(->> ((juxt identity #(partition 2 %) #(partition 3 %)) (range 9)) (apply concat))
(0 1 2 3 4 5 6 7 8 (0 1) (2 3) (4 5) (6 7) (0 1 2) (3 4 5) (6 7 8))
(apply into ((juxt empty (partial remove (comp even? val))) {:a 1, :b 2, :c 3}))
{:a 1, :c 3}
(map (juxt #(apply vector %) #(apply (comp reverse vector) %)) ["foo" "bar" "baz"])
([[\f \o \o] (\o \o \f)] [[\b \a \r] (\r \a \b)] [[\b \a \z] (\z \a \b)])
(apply group-by ((juxt identity keys) {1 3, 4 3, 32 3, 85 2, 9 2}))
{2 [85 9], 3 [1 4 32]}
(into {} (map (juxt :key :value) [{:key "the key", :value "the value"} {:key :a, :value :b}]))
{:a :b, "the key" "the value"}
(defn range-incl [a b] (apply range (map + ((juxt min max) a b) [0 1])))
#'user/range-incl
(let [foo ((partial (juxt filter remove) odd?) [1 2 3 4 5])] (take 1 (first foo)))
(1)
(map #((juxt vec (partial reduce +)) (->> (range) (filter odd?) (take %))) (range 1 11))
([[1] 1] [[1 3] 4] [[1 3 5] 9] [[1 3 5 7] 16] [[1 3 5 7 9] 25] [[1 3 5 7 9 11] 36] [[1 3 5 7 9 11 13] 49] [[1 3 5 7 9 11 13 15] 64] [[1 3 5 7 9 11 13 15 17] 81] [[1 3 5 7 9 11 13 15 17 19] 100])
(let [m ["the" "quick" "brown" "fox"]] ((juxt (partial apply max-key count) (partial apply min-key count)) m))
["brown" "fox"]
(let [map-from-fn (fn [f ks] (into {} (map (juxt identity f) ks)))] (map-from-fn inc [7 9 12]))
{7 8, 9 10, 12 13}
((apply juxt (map #(comp set %) [filter remove])) odd? #{1 2 3 4 5})
[#{1 3 5} #{2 4}]
(sort-by (juxt (comp - first) second) [[1 2] [2 1] [3 3] [2 3] [3 2]])
([3 2] [3 3] [2 1] [2 3] [1 2])
(for [i (range (count [1 2 3 4]))] ((juxt take drop) i [1 2 3 4]))
([() (1 2 3 4)] [(1) (2 3 4)] [(1 2) (3 4)] [(1 2 3) (4)])
(every? #(apply (fn [x y] (and x y)) ((juxt string? empty?) %)) (list "" ""))
true
(let [a [1 2] b [3 4] c [5 6]] ((juxt concat interleave) a b c))
[(1 2 3 4 5 6) (1 3 5 2 4 6)]
(->> (map (juxt first rest next) [() [] #{} {} nil]) (apply =) (iterate true?) (take 3) (every? true?))
true
(defn ! [x] (if (zero? x) 1 (apply * ((juxt identity #(! (dec %))) x))))
#'user/!
(->> (map (juxt first rest next) [() [] #{} {} nil]) (apply =) (iterate true?) (take 3) (apply =))
true
(apply / ((juxt first (partial apply +)) (map (frequencies (repeatedly 1000 #(rand-nth [true false]))) [true false])))
63/125
(apply conj {} (map (juxt :key :value) [{:key "the key", :value "the value"} {:key :a, :value :b}]))
{:a :b, "the key" "the value"}
((juxt (fn [x] (filter even? x)) (fn [x] (filter odd? x))) [1 2 3 4 5])
[(2 4) (1 3 5)]
(map #(map second %) ((juxt filter remove) first (for [i (range 10)] [(odd? i) i])))
((1 3 5 7 9) (0 2 4 6 8))
(map (juxt (comp dec :a) (comp inc :b)) [{:a 1, :b 2} {:a 3, :b 4}])
([0 3] [2 5])
(map first (take 3 (drop 1 (iterate (fn [[n d]] ((juxt quot rem) n 5)) [85 0]))))
(17 3 0)
(map count ((juxt identity set) (remove #{\space \, \!} "sphinx f black qurtz, jdge my vow!")))
(26 26)
(def predicator (fn [& predicates] #(apply (fn [x y] (and x y)) ((apply juxt predicates) %))))
#'user/predicator
((juxt (comp count filter) (comp count remove)) #(= "1.0" (:added %)) (map meta (vals (ns-publics 'clojure.core))))
[0 538]
(let [f (fn [& {:as opts}] ((juxt :foo :bar) opts))] (f :hello 10 :bar 42 :foo :quux))
[:quux 42]