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

Consistent index edge-case behaviour #225

Open
pbiggar opened this issue Aug 1, 2021 · 1 comment
Open

Consistent index edge-case behaviour #225

pbiggar opened this issue Aug 1, 2021 · 1 comment

Comments

@pbiggar
Copy link
Member

pbiggar commented Aug 1, 2021

When there's a function that takes a list/array/string and an index, and the index is outside the bounds of the list, some functions will raise, some wrap, some do the thing at the start/end based on where the index is, and some do the same thing regardless of whether its out-of-bounds.

They should all behave the same on all platforms. What should that behaviour be?

My preference would be, in order:

  1. normalize to valid bound
  2. normalize with wrapping
  3. raise an error if out of bounds
  4. use option/result
  5. silently return the input for out of bounds

By normalize-to-valid-bound I mean:

let index = 
  if index < 0
  then 0
  else min (length, index)

By normalize-with-wrapping I mean:

let index = 
  if index < 0
  then max (length + index), 0
  else min (length, index)
@pbiggar
Copy link
Member Author

pbiggar commented Aug 1, 2021

Also, if the same function exists for Strings, lists and/or arrays, they should behave the same.

@pbiggar pbiggar added this to the 0.2.0 milestone Oct 11, 2022
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

1 participant