constantly

added
1.0

ns
clojure.core

type
function

(constantly x)

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

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

user=> (boring 1 2 3)
10

user=> (boring)
10

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

            
                ;; A really goofy way to find the size of a collection
user=> (reduce + (map (constantly 1) [:a :b :c]))
3
            
                ;; constantly returns a function which always returns the same value
(map (constantly 9) [1 2 3])
user=> (9 9 9)

(map (constantly (rand-int 100)) [:a :b :c])
user=> (43 43 43)
            
                ;; 'Removed' example that was more about transducers than `constantly`.

:O