Skip to content

Consistent index edge-case behaviour #225

@pbiggar

Description

@pbiggar

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions