Open boathit opened 8 years ago
Actually rest
can return either:
julia> Lazy.rest(constantly(1)) |> typeof
Lazy.LazyList
Both LinkedList
and LazyList
are part of the same data structure, the List
, and should behave in exactly the same way – so there is a bug here, but that would be the wrong fix.
I'll take a look at this anyway.
I think you're right that the issue here is that rest isn't lazily evaluated, although it doesn't always need to be lazy either. We can just overload it to be equivalent to drop when applied to a lazy list.
One could also argue that rest is defined as an eager version of drop and simply shouldn't be used here, but that's probably more confusing then helpful.
In the current implementation the returned type of
rest
isLinkedList
whiledrop
returnsLazyList
,This not only seems inconsistent but also explains why the following code works unexpectedly,
If we convert the returned type of
Lazy.rest
toLazy.LazyList
it works correctly,Thus I suggest we change the returned type of
rest(::List)
toLazyList