-
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
Normative: rename to Iterator.range #59
Conversation
Codecov Report
@@ Coverage Diff @@
## main #59 +/- ##
===========================================
+ Coverage 99.39% 100.00% +0.60%
===========================================
Files 1 1
Lines 165 145 -20
Branches 57 55 -2
===========================================
- Hits 164 145 -19
+ Misses 1 0 -1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
<emu-clause id="sec-iterator.range"> | ||
<h1>Iterator.range ( _start_, _end_, _option_ )</h1> | ||
<emu-alg> | ||
1. If _start_ is a Number, return ? CreateNumericRangeIterator(_start_, _end_, _option_, ~number-range~). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn’t this coerce start and end to a primitive first, like every other builtin api?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we coerce it to a primitive, we will lose the possibility to add more overload in the future, for example, supporting a Date
range.
// for example:
Iterator.range(new Date('Jan 1 2020'), new Date(), { step: '1 day' })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like something more appropriate to put on Date (or better, on Temporal) than in this function.
spec.emu
Outdated
1. If _type_ is ~number-range~, let _primitiveType_ be *"number"*, else let _primitiveType_ be *"bigint"*. | ||
1. Assert: Type(_start_) is _primitiveType_. | ||
1. If _type_ is ~bigint-range~, let _zero_ be *0n*<sub>ℤ</sub>, else let _zero_ be *0*<sub>ℤ</sub>. | ||
1. If _type_ is ~bigint-range~, let _one_ be *1n*<sub>ℤ</sub>, else let _one_ be *1*<sub>ℤ</sub>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another alternative approach is putting Z bar or R bar in a variable, and calling it like a function (also, i don’t think both of these should be Z bar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is "Z bar" or "R bar"? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ℤ
is "Z bar", eg
1. Let _step_ be ? Get(_option_, "step"). | ||
1. Let _inclusiveEnd_ be ToBoolean(? Get(_option_, "inclusive")). | ||
1. Else if Type(_option_) is _primitiveType_, let _step_ be _option_. | ||
1. Else, throw a *TypeError* exception. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, I’d expect the options to be coerced ToObject when it’s non-nullish, rather than throwing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
I guess maybe there's a consistency argument (though I'm not sure with what?) but it seems like that would generally be unintentional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
about coerce option
, it's OK to me, but since I decided to not coerce start
, I think it will be more consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me step back - what does Temporal do with options bags? We should at least be consistent with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alrighty, fair enough. let's inline those same AOs, then, and use them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporal does what ECMA-402 does (at least, what ECMA-402 does for new APIs; there are some older Intl APIs that coerce primitives to objects). See tc39/ecma402#480
H̶̢͈̺̲͗͒̈́̈̿͆̋̋͘͝͝ơ̵͓̼̈́̏͑͊̈́͋̈́͒̕͘ļ̶̯̫̭̣̞̙̖̝͎͋̓̄͂͛̐͐̕ŷ̷̨̡̰̘̝͍̻̬͖̰̫͉̣̻̔̀͊͌̃̔̎͛́͛́̑͜͠ ̶̲̫͎̮̍̀́̔s̷̨̨̨̞̘̪̫͇͙͈̫͇̟̣̲̊́̀ͅͅh̸̡̧͕̱͖͙͎̮̐͆̌́̀͌̽̆͛͛̑͛̅̔̕͝į̴̫͈͉̩̺̹̤̹͚̖͇̰̊̊͋͌͑̃̈́̿͆͘̕͝t̸̨̨̛͇̘̠̞̼̏̈́̏̆̀̑̒̔̔͋̽͋̅̀.̴̢̤̖̀̐͂͂̊̂͆͒̇̆͐.̸̼̼̼͍̜͙̗͗̂̓̃̌̍͒̅͛͛̃͐̕̕̕͜͠.̷̡̢͚͙͇̬̳̦̫̫̓́̀̎͜ͅͅ |
It's OK to join |
just leave the possibility. not going to do it in the current proposal |
I'll merge this first, but this is not the final conclusion of renaming. I'll ask the committee if they like the rename in the next presentation. |
API Before (in TypeScript):
API now: