racket-collections
racket-collections copied to clipboard
Take and drop aren't lazy for finite sequences
For sequences that are known-finite?
, take
and drop
check the length of the input sequence eagerly before computing the result, so that something like:
(take 3 (range 10000000))
... forces the entire finite sequence, even though (range 10000000)
on its own would be lazily computed.
Possible fix: Compute the result lazily and raise an error if a point is reached where the remaining sequence is empty but more values are still expected.
It's possible this would have some backwards compatibility implications, since code that formerly would raise an error immediately would now raise the error at a later stage.