Returns its argument.
user=> (group-by identity "abracadabra") {\a [\a \a \a \a \a], \b [\b \b], \r [\r \r], \c [\c], \d [\d]}
; `identity` can serve in workarounds, because you can't pass a macro ; to a function. For example, you can't pass `and` as a parameter to `apply`: (apply and '(true 1 "yes")) ; \=> CompilerException... Can't take value of a macro... ; Instead: (every? identity '(true 1 "yes"))
Returns a function that takes any number of arguments and returns x.
It's useful for example with -> macro when we eventually want to return its argument (in this case: state)
(defn example[state] (-> state update-function-1 update-function-2 identity))
Here is another good example:
(some identity ((juxt :foo :bar) {:bar :b}))equivalent to
(let [map {:bar b}] (or (:foo map) (:bar map)))