Building Custom Collections

If none of the Clojure collections are right for your problem, you may need to roll your own. Like the standard collections, custom collections can be used seamlessly with the Clojure core library. Building a custom collection requires the use of deftype to implement the trait interfaces Clojure uses internally.

Collection Traits

If we want to build a collection that Clojure can use, we need to understand more deeply how Clojure interacts with collections. The collection and sequence libraries are based not on the particular implementations included in Clojure but on a generic set of traits that define key abstractions. Clojure collection traits are implemented internally using Java interfaces.

Predicate functions ...

Get Clojure Applied now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.