Clojure collection quirks - A REFERENCE
This is a reference of Clojure’s default data structures and the most common predicates.
Functions
This table contains the most common predicates applied to the core collections.
Seq | Vector | Map | Set | ||||||||
nil | '(1 2 3) | (range 5) | (range) (lazy-seq) (cons 1 ()) | Persistent Queue/EMPTY | [1 2 3] | (last {1 1}) | (hash-map) (array-map) | (sorted-map) | #{} | (sorted-set) | |
---|---|---|---|---|---|---|---|---|---|---|---|
type | nil | Persistent List | LongRange | Iterate or LazySeq or Cons | Persistent Queue | Persistent Vector | MapEntry | Persistent ArrayMap or HashMap | Persistent TreeMap | Persistent HashSet | Persistent TreeSet |
coll? | false | true | true | true | true | true | true | true | true | true | true |
counted? | false | true | true | false | true | true | true | true | true | true | true |
ifn? | false | false | false | false | false | true | true | true | true | true | true |
associative? | false | false | false | false | false | true | true | true | true | false | false |
map? | false | false | false | false | false | false | false | true | true | false | false |
sequential? | false | true | true | true | true | true | true | false | false | false | false |
list? | false | true | false | false | true | false | false | false | false | false | false |
seq? | false | true | true | true | false | false | false | false | false | false | false |
reversible? | false | false | false | false | false | true | true | false | true | false | true |
vector? | false | false | false | false | false | true | true | false | false | false | false |
map-entry? | false | false | false | false | false | false | true | false | false | false | false |
map? | false | false | false | false | false | false | false | true | true | false | false |
set? | false | false | false | false | false | false | false | false | false | true | true |
sorted? | false | false | false | false | false | false | false | false | true | false | true |
Interfaces
An incomplete list of some of the most commonly used default Clojure interfaces found in the clojure.lang
package.
IMeta
The object has meta information accessible via the (meta x)
function.
IObj
Indicates that meta information can be added to object (with-meta
function).
Counted
This collection supports fast counting ((count x)
function call).
IEditableCollection
A transient version of the collection can be created with the (transient x)
call.
IFn
Indicates that he object can be called just like a function.
IKeywordLookup
A collection supports indexing by keywords.
ILookup
Collection supports access by index (via get
function with default value).
IPending
Supports realized?
function.
IPersistentCollection
Persistent collections have support for conj
, empty
, count
, equals
functions.
ISeq
Sequences have support for first
, next
, rest
, cons
functions.