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
Float-based ranges #9339
Comments
The use case is almost identical to #9327 and the solutions discussed there (e.g. #9327 (comment)) should work for any non-discrete type, including floats. |
Agreed, the |
The only other type in stdlib that implements So instead we could create a proper interface for that. Maybe But actually, this method already exists and even shares the name and intention: So there is a very easy solution: |
@straight-shoota brilliant! |
The implementation of It seems like a good idea to move the implementation out of |
Proposal: It would be help in many situations to make the Range(Float64, Float64) and Range(Float32, Float32) types enumerable with a step size (default to 1).
One potential pain point is the constructor requiring three arguments instead of 2 now so the X..Y syntax won't work if one wants to specify the delta.
Looking at the code in "range.cr" I think a simple way to get at the enumeration is to put an internal function to the range that does a responds_to?(:succ) on the current range element to either use the provided method or to try and infer it by doing something like current + step_size. A slight downside of this is that now the underlying type needs an operator+ defined.
The text was updated successfully, but these errors were encountered: