Cover by Brian Carper, Christophe Grand, Chas Emerick

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Putting Clojure’s Collections to Work

Why are data structures so important? In The Mythical Man-Month, Frederick Brooks says:

Show me your flowchart and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won’t usually need your flowchart; it’ll be obvious.

Two decades later, Eric Raymond modernized it into:

Show me your code and conceal your data structures, and I shall continue to be mystified. Show me your data structures, and I won’t usually need your code; it’ll be obvious.

The way you structure and model your data determines the shape of your code; hence, you cannot write good functional Clojure code if you persist with old habits, modeling everything out of arrays, dedicated objects, and the occasional map.

Modeling data well in Clojure puts the focus on values (and particularly composite values), natural identifiers, and sets and maps. The mindset to adopt is akin to the one for relational[108] modeling. However, what constitutes a value is highly context-dependent: thanks to composite values, a value can be hierarchical, so it’s up to the developer to define the granularity at which relationships are maintained.

Identifiers and Cycles

Natural identifiers are opposed to synthetic or surrogate identifiers, where the latter are usually strings or an artificially generated number, akin to sequences or autoincrements in databases or object references themselves in most object-oriented languages. Thus, synthetic identifiers are by definition artifacts ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required