Skip to content

clojure.core/identity

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 8 Runnable: 6
([x])

Returns its argument.

Examples

by dpritchett on
by cschreiner on
by cschreiner on
by cschreiner on . May have evaluation errors.
by shockbob on
by OnesimusUnbound on
by protsenkovi on
by peter-kehl on . May have evaluation errors.

Note by Jacolyte

I don't quite see the usefulness of this :P

Note by dturczanski

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))

Note by lancepantz

Here is another good example:

(some identity ((juxt :foo :bar) {:bar :b}))

equivalent to

 (let [map {:bar b}] (or (:foo map) (:bar map)))

### Note by tlightsky

user=> (mapcat identity [[[0 1] [1 2]] [[11 12]]])
([0 1] [1 2] [11 12])



## See also




---

Content from [the matching ClojureDocs page](https://clojuredocs.org/clojure.core/identity), with authors
credited on each contribution.