-
Notifications
You must be signed in to change notification settings - Fork 23
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
Range Types #96
Range Types #96
Conversation
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.
Nice! I like the Range
and Progression
types because they are nicely extensible; we could later allow people to iterate over any kind of comparable type (strings, addresses, etc) if we lift the restriction that the type argument here be an Integer
. A couple of suggestions though:
I don't think Range
and Progression
actually need to be different types, since a Range
is just a special case of the more general Progression
type where the step
is a specific default value (in this case 1
or -1
). I suggest that we combine these into one Range
type that can be given a step
if the developer wishes, but otherwise uses these defaults.
Additionally, I think we don't need the specific downTo
operator; all this is really doing is making the step
negative.
What if instead the range was always defined with ..
, and the sign of the step
is automatically inferred from whether the start or end value is greater. We could also imagine a syntax like let range = x, y .. z
where the start
of this range is x
, the end is z
, and the step is y-x
. Rephrased, developers could define the sequence by giving it a start and end, and if they want the step to be something other than +/- 1
, they can define the second element of the range and the step is automatically inferred based on 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.
Nice! Thank you for writing up this proposal 👍
Co-authored-by: Daniel Sainati <sainatidaniel@gmail.com>
@turbolent @dsainati1 Thanks for your review comments. I agree with all of the suggestions and will modify the FLIP with the following new proposal: We will not have operators to create a The only source of confusion for me is whether we want to unify For unified, the constructors will be For separate, the constructors will |
IMO it's better to have them be one type, if only because the names are clearer. IMO the function name |
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.
Nice! I like this proposal a lot more after the changes, it seems like it's going to be a nice feature.
Updated the FLIP
|
Can we have a helper method that has some defaults? For instance for IntRange having it as step 1 is a start. Also what about specifying length and not end? |
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Co-authored-by: Bastian Müller <bastian@turbolent.com>
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.
The overall design looks good to me!
The step argument in the constructor is optional. It already supports step of 1 or -1.
Sounds useful but I think the argument against |
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.
Nice, LGTM!
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.
Looks good to me! Thanks for the hard work
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.
Nice! 🚀
Let's leave this open for another week to invite additional feedback. If there's no additional feedback the FLIP is ready to get accepted and merged 🎉 |
Work towards onflow/developer-grants#179