February 2018
Intermediate to advanced
304 pages
7h 11m
English
The seq abstraction of first/rest applies to anything that there can be more than one of. In the Java world, that includes the following:
Clojure wraps these Java APIs, making the sequence library available for almost everything you do.
If you try to apply the sequence functions to Java collections, you’ll find that they behave as sequences. Collections that can act as sequences are called seq-able. For example, arrays are seq-able:
| | ; String.getBytes returns a byte array |
| | (first (.getBytes "hello")) |
| | -> 104 |
| | |
| | (rest (.getBytes "hello")) |
| | -> (101 108 108 111) |
| | |
| | (cons (int \h) (.getBytes ... |