(let [[a b] (repeatedly #(atom 0))] ((juxt = identical?) a b))
[false false]
(map (juxt :a :b) [{:a "a", :b "b"} {:a "a1", :b "b1"}])
(["a" "b"] ["a1" "b1"])
(map apply [inc dec] ((juxt (comp vector inc) (comp vector dec)) 0))
(2 -2)
((juxt #(get % 1) #(get % 2)) [1 3 5])
[3 5]
(let [f (juxt first second last)] (f [1 2 3 4 5]))
[1 2 5]
(sorted-set-by #(compare ((juxt :estimate identity) %1) ((juxt :estimage identity) %2)) {:estimate 8, :val -1} {:estimate 1, :val 42} {:estimate 1, :val 100} {:estimate :2, :val 33})
#{{:estimate 8, :val -1} {:estimate 1, :val 100} {:estimate :2, :val 33} {:estimate 1, :val 42}}
(let [m (apply array-map (range 100))] ((juxt class count) (dissoc m 0)))
[clojure.lang.PersistentArrayMap 49]
(take 6 (iterate #(mapcat (juxt count first) (partition-by identity %)) [1]))
([1] (1 1) (2 1) (1 2 1 1) (1 1 1 2 2 1) (3 1 2 2 1 1))
((juxt :a :d :c) {:a 3, :b 5, :c 8, :d 1})
[3 1 8]
(map (juxt :a :b) [{:a 1, :b 2} {:a 5, :b 7}])
([1 2] [5 7])
(apply concat ((juxt take (comp rest drop)) 2 [1 2 3 4]))
(1 2 4)
(sort-by (juxt :foo :bar) [{:foo "x", :baa "a"} {:foo "y", :bar "b"}])
({:baa "a", :foo "x"} {:bar "b", :foo "y"})
((juxt #(reduce + %) #(reduce - %)) [1 2 3])
[6 -4]
(map (partial juxt [+ - *] [1 2 3]) [4 5 6])
(#object [clojure.core$juxt$fn__5893 0x2561384c "clojure.core$juxt$fn__5893@2561384c"] #object [clojure.core$juxt$fn__5893 0x2ba6d290 "clojure.core$juxt$fn__5893@2ba6d290"] #object [clojure.core$juxt$fn__5893 0x2f99533c "clojure.core$juxt$fn__5893@2f99533c"])
((juxt (fn [[_ & rest]] rest) (fn [x] (rest x))) (range 10))
[(1 2 3 4 5 6 7 8 9) (1 2 3 4 5 6 7 8 9)]
(map (juxt identity seq? coll?) ['(:list) [:vector] {:a :map} #{:set}])
([(:list) true true] [[:vector] false true] [{:a :map} false true] [#{:set} false true])
((apply juxt [:a :b]) {:a 1, :b 2, :c 3, :d 4})
[1 2]
(into {} (map (juxt keyword #(str % (.toUpperCase %))) ["a" "b" "c"]))
{:a "aA", :b "bB", :c "cC"}
((juxt :foo :bar :baz) {:bar 'b, :baz 'c, :foo 'a, :woz 'd})
[a b c]
(into {} (map (juxt (comp keyword str) identity) [0 1 2 3 4]))
{:0 0, :1 1, :2 2, :3 3, :4 4}
((juxt (partial map first) (partial map second)) [[1 2] [1 3] [1 4]])
[(1 1 1) (2 3 4)]
((juxt first rest) (rest (re-matches #"(.*);(.*):(.*)" "235;2352:33")))
["235" ("2352" "33")]
(map (juxt type identity) (let [x 1] `[~x x 'x '~x ~'x]))
([java.lang.Long 1] [clojure.lang.Symbol user/x] [clojure.lang.Cons (quote user/x)] [clojure.lang.Cons (quote 1)] [clojure.lang.Symbol x])
(into {} (map (juxt (comp keyword str) (constantly 0)) [0 1 2 3 4]))
{:0 0, :1 0, :2 0, :3 0, :4 0}
(let [m [1 4 2 7 8 5]] (apply (juxt min max) m))
[1 8]
((comp first (partial nth (iterate (juxt second (partial apply +)) [1 1]))) 6)
13
(take 5 (for [i (range)] ((juxt take drop) i [1 2 3 4])))
([() (1 2 3 4)] [(1) (2 3 4)] [(1 2) (3 4)] [(1 2 3) (4)] [(1 2 3 4) ()])
(map (juxt (constantly 1) inc (constantly 2) dec (constantly 3)) [5 10 15])
([1 6 2 4 3] [1 11 2 9 3] [1 16 2 14 3])
(map (comp (partial interleave [1 2 3]) (juxt inc dec)) [5 10 15])
((1 6 2 4) (1 11 2 9) (1 16 2 14))
((juxt (partial map first) (partial map second)) [[1 2] [3 4] [5 6]])
[(1 3 5) (2 4 6)]
((juxt first second) (partition 2 [1 2 3 4 5 6 7 8]))
[(1 2) (3 4)]
(into {} (map (juxt :name identity) [{:name "al", :job "mcdonalds"} {:name "joe", :job "president"}]))
{"al" {:job "mcdonalds", :name "al"}, "joe" {:job "president", :name "joe"}}
(let [m ["the" "quick" "brown" "fox"]] (apply (partial (juxt max-key min-key) count) m))
["brown" "fox"]
(into {} (map (juxt key (comp inc val)) {:a 1, :b 2, :c 3}))
{:a 2, :b 3, :c 4}
(defn build-table' [coll] (map (juxt identity #(filter (partial >= %) coll)) coll))
#'user/build-table'
(sorted-set-by #(compare ((juxt :estimate vec) %1) ((juxt :estimate vec) %2)) {:estimate 8, :val -1} {:estimate 1, :val 42} {:estimate 1, :val 100} {:estimate 2, :val 33})
#{{:estimate 8, :val -1} {:estimate 1, :val 100} {:estimate 2, :val 33} {:estimate 1, :val 42}}
(map (apply juxt [:a :b]) [{:a 1, :b 2} {:a 5, :b 7}])
([1 2] [5 7])
((fn rle [s] (apply str (mapcat (juxt count identity) (partition-by identity s)))) "aaabddcejkkeddddddd")
"3(\\a \\a \\a)1(\\b)2(\\d \\d)1(\\c)1(\\e)1(\\j)2(\\k \\k)1(\\e)7(\\d \\d \\d \\d \\d \\d \\d)"
(map (juxt :a :b) [{:a 0, :b 3} {:a 5, :b 42}])
([0 3] [5 42])
(filter (juxt inc dec) [1 2 3 4 5 6 7 8 9])
(1 2 3 4 5 6 7 8 9)
(let [m {:a 1, :b 2, :c 3}] ((apply juxt (keys m)) m))
[1 2 3]
(map second (sort-by first (map (juxt rand identity) [5 4 3 2 1])))
(1 2 4 3 5)
(->> {:a 3, :b 2, :c 1} (sort-by val) (map (juxt identity type)))
([[:c 1] clojure.lang.MapEntry] [[:b 2] clojure.lang.MapEntry] [[:a 3] clojure.lang.MapEntry])
((juxt #(filter even? %) #(filter odd? %)) [1 2 3 4])
[(2 4) (1 3)]
(let [m [1 4 2 7 8 5]] ((juxt first last) (sort m)))
[1 8]
(every? true? (apply map > ((juxt rest seq) [1 3 4 6 7])))
true
(some (partial apply =) ((comp (partial apply map list) (juxt identity rest)) "somestring"))
nil
(some (partial apply =) ((comp (partial apply map list) (juxt identity rest)) "someestring"))
true
(->> {:a 10, :b 20, :c 30} ((juxt :a :b :c :d)) (sort))
(nil 10 20 30)
(defn count-true [input & preds] (->> input ((apply juxt preds)) (filter true?) (count)))
#'user/count-true