Reducible sequence generators

Description

Have iterate, cycle, and repeat return custom types that are directly reducible.

Background and inspiration are and http://insideclojure.org/2015/01/18/reducible-generators/

While (satisfies? IReduce (iterate inc 0)) returns true this is via LazySeq, as opposed to, for example (satisfies? IReduce (range)) which involves a custom type.

One motivation would be the ability to transduce over large generated collections without consuming memory (which otherwise occurs due to lack of locals clearing).

For example, the following uses very little memory:

1 (transduce (comp (map inc) (filter odd?) (take 1e8)) + (range))

where this semantically equivalent form consumes gigabytes:

1 (transduce (comp (map inc) (filter odd?) (take 1e8)) + (iterate inc 0))

It is expected that, to implement this ticket, three new types would be introduced, akin to the existing Range class, porting as much as possible from the existing types implemented in Clojure for iterate, cycle, and repeat.

Environment

None

Status

Assignee

David Nolen

Reporter

Mike Fikes

Labels

Approval

Accepted

Patch

Code and Test

Affects versions

1.9.908

Priority

Major