You're viewing version 1.2.0 of identity. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

identity

clojure.core

  • (identity x)
Returns its argument.

6 Examples top

  • user=> (identity 4)
    4
  • user=> (filter identity [1 2 3 nil 4 false true 1234])
    (1 2 3 4 true 1234)
  • user=> (map #(%1 %2) (cycle [inc identity]) [1 2 3 4 5 6 7 8 9 10])
    (2 2 4 4 6 6 8 8 10 10)
    
  • user=> (partition-by identity (sort "abcdaabccc"))
    ((\a \a \a) (\b \b) (\c \c \c \c) (\d))
    
  • user=> (map first (partition-by identity [1 1 2 3 3 1 1 5 5]))
    (1 2 3 1 5)
  • user=> (group-by identity "abracadabra")
    {\a [\a \a \a \a \a], \b [\b \b], \r [\r \r], \c [\c], \d [\d]}
Log in to add / edit an example.

See Also top

Log in to add a see also.

Comments top

3 comment(s) for identity.

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

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


	
Log in to add a comment.