parzh / xrange

Python-esque iterator for number ranges
https://npmjs.org/package/xrange
0 stars 0 forks source link

Save start, stop, and step as properties of range #59

Open parzhitsky opened 4 years ago

parzhitsky commented 4 years ago

In case of numeric implementation, save start, stop, and step as properties of range:

const { start, stop, step } = xrange(10);

start; // 0
stop; // 10
step; // 1
const { start, stop, step } = xrange(2, -3);

start; // 2
stop; // -3
step; // -1
const { start, stop, step } = xrange(42, 17, 5);

start; // 17
stop; // 42
step; // 5
const range = xrange(7, () => true, Math.random);
const { start, stop, step } = range;

start; // undefined
stop; // undefined
step; // undefined

"stop" in range; // true
"step" in range; // true
parzhitsky commented 4 years ago

This requires implementing a wrapper around core (@xrange/core) or reimplementing core to plain (although iterator-protocol-compliant) object, rather than a generator.

parzhitsky commented 4 years ago

Blocked by parzh/xrange__core#13

parzhitsky commented 2 years ago

start of a functional iterator is changed to undefined to address parzh/xrange#48