-
Notifications
You must be signed in to change notification settings - Fork 97
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
Proposal: add arguments to int()
to guard value and add default
#431
Comments
@skiars any opinion for or against it? If not I will implement it as described above. |
I'm a bit confused about the use of Gating of numeric ranges is typically done using specialized functions, which helps in maintaining semantic clarity. I would suggest adding these to the math library: def min(a, b)
return a < b ? a : b
end
def max(a, b)
return a > b ? a : b
end
def bound(lower, value, upper)
return max(lower, min(value, upper))
end |
Thanks, using a default value was indeed a bad idea and makes the syntax confusing. I agree that min/max are missing. But then the syntax would be:
|
The
|
int()
currently takes only one argument, and returnnil
if the argument isnil
I'm facing a lot of code where I need to guard the value within a range and potentially define a default value.
I'm proposing to have new optional arguments:
int(arg:any, [min: int, max: int, def: int or nil]) -> int or nil
With this the above code would look like:
It could also used without a default value, hence forcing an
int
between0
and100
ornil
@skiars any opinion on this proposal?
Note: code impact would be minimal, and no impact on performace
The text was updated successfully, but these errors were encountered: