Skip to content
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

Adjust the behaviour of arrange to match list.range. #35

Open
hayleigh-dot-dev opened this issue Dec 14, 2024 · 1 comment
Open

Adjust the behaviour of arrange to match list.range. #35

hayleigh-dot-dev opened this issue Dec 14, 2024 · 1 comment

Comments

@hayleigh-dot-dev
Copy link
Member

Currently the arrange function compares start and stop and checks if that agrees with the increment argument. If start is greater than stop and increment is positive, the function bails with an empty yielder.

I'd like to float the idea of matching behaviour with list.range but with the step be configurable so...

arrange(1.0, 5.0, 1.0)  // [1.0, 2.0, 3.0, 4.0, 5.0]
arrange(5.0, 1.0, 1.0)  // [5.0, 4.0, 3.0, 2.0, 1.0]

arrange(1.0, 5.0, -1.0) // [5.0, 4.0, 3.0, 2.0, 1.0]
arrange(5.0, 1.0, -1.0) // [1.0, 2.0, 3.0, 4.0, 5.0]

The thinking being we also generate from the first argument to the second argument using the positive step size provided. In cases where the step size is negative we generate backwards from the second argument to the first.

In the common case this would match the behaviour of list.range, what do you think?

@NicklasXYZ
Copy link
Member

NicklasXYZ commented Dec 17, 2024

I think if we want to keep things as simple as possible, then the current behavior is better. As I see it, the proposed behavior would introduce ambiguity by allowing two ways to generate the same progression of values. In particular, it would change how the increment/step argument is interpreted: the sign of the increment/step would be ignored when reversing the range direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants