-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configuration parameter #25
Comments
As #7
As #26
And
|
I like the idea of the step parameter being provided with an entry in the options bag. In addition to making the API more extensible (without requiring everyone to fill in |
@hax The "count" parameters can be done by: |
Yeah, I'm pretty skeptical of the options given in #25 (comment) . |
No. What I listed have a totally different semantic. BigInt.range(10n, 20n, {count: 3n}) // 10n, 14n, 18n
BigInt.range(10n, 20n).take(3) // 10n, 11n, 12n
@littledan I just listed some possibilities in my mind (like we did for many other proposals), I don't mean any of those options are urgent to add to this proposal. |
Although we don't have a consense now about what options should be included in this proposal, I think it seems okay to accept an options object - Number.range(from: number, to: number, step?: number)
+ Number.range(from: number, to: number, step?: number)
+ Number.range(from: number, to: number, options?: { step?: number }) But how to expose supported options (so that polyfill authors can decide if they need to polyfill for new options)?
|
@Jack-Works Yeah, this is a general problem with options bags and feature testing... You can do a test call of |
Oh cool trick, I didn't know that before |
Personally I would write small test like: try { Number.range(1, 3, {step:-1}) } catch {
// feature detected!
return
}
// do polyfill |
@hax I don't think it is a good idea to throw for unknown options.. 🤔 |
Please check out #27 (it won't close this issue) |
Feature detection for specific options is not necessary unless a browser ships an incomplete implementation. Since |
It is possible that we might add new options in the future after browser shiped this so feature detection might be necessary in the future |
@Jack-Works const r = Number.range(1, 4, {step:2})
r.next()
if (r.next().value === 3)
// feature detected!
return
}
// do polyfill |
This comment has been minimized.
This comment has been minimized.
@leobalter I don't understand; how would a mapping function meet the use cases of the options parameter? |
@littledan please never mind. In a second thought I don't think I want a mapping function anyway. |
I have considered things like |
I expect this sort of use case would commonly be satisfied using
And eventually we may have https://github.com/tc39/proposal-iterator-helpers |
@hax:
How is this different from |
@tabatkins The results have no difference. It just provide another way to describe the iteration. Of coz u can calculate the |
In #7 (comment) @hax proposed the 3rd parameter to also accept an object to allow configuration.
let's discuss does it useful and what behavior can be configured here.
Possible usages:
custom step function (last, index) => next(Can be done with iterator helper proposal)The text was updated successfully, but these errors were encountered: