store/[org.clojure/clojure "1.8.0"] clj::clojure.core/juxt

Official Documentation

Add notes
Arities
==================================================
   [f]
   [f g]
   [f g h]
   [f g h & fs]

Docstring
==================================================
  Takes a set of functions and returns a fn that is the juxtaposition
  of those fns.  The returned fn takes a variable number of args, and
  returns a vector containing the result of applying each fn to the
  args (left-to-right).
  ((juxt a b c) x) => [(a x) (b x) (c x)]

Source

(defn juxt 
  "Takes a set of functions and returns a fn that is the juxtaposition
  of those fns.  The returned fn takes a variable number of args, and
  returns a vector containing the result of applying each fn to the
  args (left-to-right).
  ((juxt a b c) x) => [(a x) (b x) (c x)]"
  {:added "1.1"
   :static true}
  ([f] 
     (fn
       ([] [(f)])
       ([x] [(f x)])
       ([x y] [(f x y)])
       ([x y z] [(f x y z)])
       ([x y z & args] [(apply f x y z args)])))
  ([f g] 
     (fn
       ([] [(f) (g)])
       ([x] [(f x) (g x)])
       ([x y] [(f x y) (g x y)])
       ([x y z] [(f x y z) (g x y z)])
       ([x y z & args] [(apply f x y z args) (apply g x y z args)])))
  ([f g h] 
     (fn
       ([] [(f) (g) (h)])
       ([x] [(f x) (g x) (h x)])
       ([x y] [(f x y) (g x y) (h x y)])
       ([x y z] [(f x y z) (g x y z) (h x y z)])
       ([x y z & args] [(apply f x y z args) (apply g x y z args) (apply h x y z args)])))
  ([f g h & fs]
     (let [fs (list* f g h fs)]
       (fn
         ([] (reduce1 #(conj %1 (%2)) [] fs))
         ([x] (reduce1 #(conj %1 (%2 x)) [] fs))
         ([x y] (reduce1 #(conj %1 (%2 x y)) [] fs))
         ([x y z] (reduce1 #(conj %1 (%2 x y z)) [] fs))
         ([x y z & args] (reduce1 #(conj %1 (apply %2 x y z args)) [] fs))))))

Example 1

Edit
;; Get the first character and length of string

((juxt first count) "Clojure Rocks")
;; => [\C 13]

Example 2

Edit
;; Extract values from a map.

((juxt :a :b) {:a 1 :b 2 :c 3 :d 4})
;; => [1 2]

Example 3

Edit
;; "Explode" a value.

((juxt identity name) :keyword)
;; => [:keyword "keyword"]


;; eg. to create a map:

(into {} (map (juxt identity name) [:a :b :c :d]))
;; => {:a "a" :b "b" :c "c" :d "d"}

Example 4

Edit
;; sort list of maps by multiple values
(sort-by (juxt :a :b)
         [{:a 1 :b 3} {:a 1 :b 2} {:a 2 :b 1}])
;; => [{:a 1 :b 2} {:a 1 :b 3} {:a 2 :b 1}]

Example 5

Edit
;; Create lookup maps via a specific key

(defn index-by [coll key-fn]
  (into {} (map (juxt key-fn identity) coll)))
;; => #'user/index-by

(index-by [{:id 1 :name "foo"} 
           {:id 2 :name "bar"} 
           {:id 3 :name "baz"}] :id)
;; => {1 {:name "foo", :id 1}, 2 {:name "bar", :id 2}, 3 {:name "baz", :id 3}}

(index-by [{:id 1 :name "foo"} 
           {:id 2 :name "bar"} 
           {:id 3 :name "baz"}] :name)
;; => {"foo" {:name "foo", :id 1}, "bar" {:name "bar", :id 2}, "baz" {:name "baz", :id 3}}

Uses on crossclj