O'Reilly logo

Clojure for Domain-specific Languages by Kelker Ryan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sequences

Clojure sequences implement the ISeq interface to make a thread-safe logical list. Sequences produced by functions in Clojure are usually lazy. This means that a value within the list isn't computed until the value is needed.

Learning to manipulate sequences will save you both time and many lines of code. Some sequence manipulation forms do the same thing and only differ by execution speed. Please be sure to pay extra attention when execution times are displayed in the examples.

Sequences by example

To test if an object implements the ISeq interface, use the seq? form:

user> (seq? [1])
false
user> (seq? (seq [1]))
true
user> (seq [])
nil

When nil isn't an acceptable value, use the sequence form to return an empty sequence instead of nil ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required