A collection holds multiple values for operations such as counting, access, traversal, and transformation. Clojure’s collection functions work across its own data structures, and many also accept Java collections or arrays. That interoperability lets Java-provided data enter ordinary collection-processing code, though each function has its own input contract. section 8.5 section 8.0
Check the operation’s contract rather than assuming every input behaves alike:
- `count` returns the number of elements in a collection; `(count nil)` is `0`. What counts as an element depends on the type: map entries are counted as tuples, while record fields are counted as fields. Scalars such as numbers cannot be counted. section 8.1.2
- `set` accepts a collection, including common Java iterable types, and produces a Clojure set with duplicates removed. Empty or nil input produces an empty set; non-collection input raises `IllegalArgumentException`. section 13.2
- Performance depends on the input structure. Counting a vector is O(1), while counting a lazy sequence is O(n). A polymorphic function is convenient, but its cost is not necessarily uniform. section 8.1.2 section 8.0
Count values or remove duplicates
(count [1 2 3]) ;; 3 (set [1 2 3 4 1 4]) ;; #{1 4 3 2} Use `count` when a decision depends on size, such as checking command-line arguments. Use `set` when subsequent work needs distinct values; `contains?` can then test membership. The same `set` operation can consume supported Java iterable inputs. section 8.1.2 section 13.2
Collections are the broad container abstraction; sequences are a more specialized abstraction. Standard functions often bridge the two, so choose an operation for the job, then check its accepted inputs and any type-specific cost. section 8.5 section 8.3















