6.3.90.900
2 Examples
Obviously, the primary purpose of generic collections is the ability to operate on values in a
collection-agnostic way. For example, it is possible to map over all kinds of sequences, even
sequences of heterogenous types.
However, more interesting applications of generic collections involve the ability to use lazy
sequences to create infinite streams of values. For example, it is possible to create an infinite
stream of all the Fibonacci numbers:
Similarly, here is an implementation of the classic
“fizz buzz” problem that uses
infinite sequences:
|
|
|
|
> (sequence->list (take 20 fizzbuzz)) |
'(1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizzbuzz 16 17 fizz 19 buzz) |