tc39 / proposal-iterator.range

A proposal for ECMAScript to add a built-in Iterator.range()
https://tc39.es/proposal-iterator.range/
MIT License
487 stars 13 forks source link

Add helper functions on %RangeIteratorPrototype% #12

Closed Jack-Works closed 4 years ago

Jack-Works commented 4 years ago

Return a Range object with a @@iterator or extends %RangeIteratorPrototype% so we can add some helper functions on the range object like range.includes()

Possible methods on the Range object

chicoxyzzy commented 4 years ago

Does that also means introducing new Range type with possible static methods on it? Should two new types Number.Range and Bigint.Range be presented then?

Jack-Works commented 4 years ago

yes, I think it will be useful but I'm not quite clear about what will the API looks like maybe some investigation on other languages

chicoxyzzy commented 4 years ago

Some possible instance and static methods:

Jack-Works commented 4 years ago

Maybe not making a Range object, but add useful methods on %RangeIteratorPrototype%.

There're complains that said Number.range is too long, and make Range a class will even longer ((new Number.range()).includes())

By adding methods on the %RangeIteratorPrototype%, we can use it like Number.range(a, b).isFinite().

Jack-Works commented 4 years ago

For the convenience of future polyfill, IMO it should also expose 3 getters (or non-writable values) start, end and step to expose its internal slot.

Jack-Works commented 4 years ago

Yes, we're going to have helper methods. I'm closing this issue. If anyone wants to suggest any helpers, please open a new issue. That will make the discussion easier to track.