ClojureDocs

Nav

Namespaces

hash-set

clojure.core

Available since 1.0 (source)
  • (hash-set)
  • (hash-set & keys)
Returns a new hash set with supplied keys.  Any equal keys are
handled as if by repeated uses of conj.
2 Examples
;; Any duplicates are squashed (no error)
(hash-set 1 2 1 3 1 4 1 5)
;;=> #{1 4 3 2 5}

;; There is an equivalent reader macro '#{...}'
(= (hash-set :c :a :b) #{:b :a :c})
;;=> true 

;; A string can be treated as a sequence to produce
;; a set of the characters found in the string.
(apply hash-set (seq "Lorem ipsum dolor sit amet"))
;;=> #{\space \a \d \e \i \L \l \m \o \p \r \s \t \u}

;; or simply (see "set")
(set "Lorem ipsum dolor sit amet")
;;=> #{\space \a \d \e \i \L \l \m \o \p \r \s \t \u}
;; The "equivalent" reader macro throws an error when receiving duplicates, however:
#{ 1 2 1 }
;;=> Duplicate key: 1
See Also

Returns a new sorted set with supplied keys. Any equal keys are handled as if by repeated uses of...

Added by timgilbert

Returns a set of the distinct elements of coll.

Added by reborg
0 Notes
No notes for hash-set