3 ms·
You can treat any collection or data structure that implements the sequence protocol as a lazy sequence with (seq collection) But you don't have to. If yo
by greggyb 7y ago
You can treat any collection or data structure that implements the sequence protocol as a lazy sequence with
(seq collection)
But you don't have to. If you choose to, you're not tied to a representation of mutable cons cells. There are good reasons to want to iterate over values in a map or a set, while still wanting the lookup characteristics of those collections, rather than a linked list.
This is hardly a controversial stance. Python, for example, supports iteration over many of its data structures and it is recommended to implement the dunder methods for iteration on any class that might reasonably be the basis of an iteration.
All clojure does is agree that iteration over a lazy sequence is a valuable concept. It implements this as an abstract protocol, rather than as a concrete implementation on linked lists.