Skip to content

Very lazy LazyList creation #11105

Closed
Closed
@NthPortal

Description

@NthPortal

Currently, LazyList has two forms of laziness:

  1. laziness in determining whether or not it is empty (and by extension, how many elements it has)
  2. independent laziness of elements - that is, evaluating a subsequent head or tail of the LazyList does not cause the evaluation of previous heads.

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 LazyLists as well.

In theory, #::: can be used to combine LazyLists 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions