tc39 / proposal-iterator.range

A proposal for ECMAScript to add a built-in Iterator.range()

Home Page:https://tc39.es/proposal-iterator.range/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add helper functions on %RangeIteratorPrototype%

Jack-Works opened this issue · comments

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

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?

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

Some possible instance and static methods:

  • Number.Range.isFinite()
  • Number.Range.prototype.toLocaleString([locales [, options]])
  • BigInt.Range.prototype.toLocaleString([locales [, options]])

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().

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.

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.