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

Official Documentation

Add notes
Arities
==================================================
   [x]

Docstring
==================================================
  Returns a function that takes any number of arguments and returns x.

Source

(defn constantly
  "Returns a function that takes any number of arguments and returns x."
  {:added "1.0"
   :static true}
  [x] (fn [& args] x))

Example 1

Edit
;; A really goofy way to find the size of a collection
(reduce + (map (constantly 1) [:a :b :c]))
;; => 3

Example 2

Edit
;; constantly returns a function which always returns the same value
(map (constantly 9) [1 2 3])
;; => (9 9 9)

(map (constantly (rand-int 100)) [:a :b :c])
;; => (43 43 43)

Example 3

Edit
(def boring (constantly 10))
;; => #'user/boring

(boring 1 2 3)
;; => 10

(boring)
;; => 10

(boring "Is anybody home?")
;; => 10

Uses on crossclj