Description
Currently, LazyList
has two forms of laziness:
- laziness in determining whether or not it is empty (and by extension, how many elements it has)
- independent laziness of elements - that is, evaluating a subsequent
head
ortail
of theLazyList
does not cause the evaluation of previoushead
s.
Of LazyList
's factory methods, none support both kinds of laziness. unfold
and from
(when called with an Iterator
or View
) support the first kind, but have to evaluate previous elements in order to know if the collection contains subsequent elements. tabulate
, fill
and continually
support the second kind of laziness, but their sizes are known at construction (infinity in the case of continually
). The lazy #::
method can only be used to create non-empty LazyList
s as well.
In theory, #:::
can be used to combine LazyList
s of 0 or 1 elements which are lazy in the first way, thus making the elements independently lazy; however, this seems to have poor usability both from API and performance perspectives (also it may not be stack-safe).
What factory method (or other strategy) can we use to create a LazyList
with both kinds of laziness? Is this even a useful feature? I do not personally have a motivating example, but that doesn't mean that none exists.