We're updating the issue view to help you get more done. 

New iterate and cycle impls have delayed computations but don't implement IPending

Description

When moving from LazySeqs to the new types we lost this but I don't think we should. Tools like Cursive use this for deciding when and how much to realize from a lazy sequence.

Approach:

  • iterate - The head of an iterate will always have the seed value and return 1 realized value. Subsequent elements will start unrealized and then become realized when the iterate function has been invoked to produce the value.

  • cycle - Returns unrealized if _current has been forced (initially null for all nodes after the first node).

(Note that range and repeat effectively always have their first element realized so I have chosen not to implement IPending - there is no delayed computation pending.)

1 2 3 4 5 6 7 8 9 10 11 12 ;; setup (def i (iterate inc 0)) (def c (cycle [1 2 3])) user=> (mapv realized? [i (next i) c (next c)]) [true false true false] user=> (fnext i) 1 user=> (fnext c) 2 user=> (mapv realized? [i (next i) c (next c)]) [true true true true]

Patch: clj-1726-2.patch

Environment

None

Status

Assignee

Unassigned

Reporter

Alex Miller

Labels

Approval

Ok

Patch

Code

Fix versions

Affects versions

Release 1.7

Priority

Major