grain icon indicating copy to clipboard operation
grain copied to clipboard

Stdlib: Negative indexing discussion

Open phated opened this issue 3 years ago • 1 comments

In the stdlib, there are some methods (such as List.insert, List.take, List.drop, etc) that fail upon receiving a negative number. This is different than the behavior of something like String.slice, which treats the negative index as an offset from the end of the value.

So, I was thinking for consistency sake (and to avoid as many fail in the stdlib as possible) that any methods that use indexes in the stdlib should treat negative indexes as an offset from the end of the list. e.g. List.take(-2, myList) would take the 2nd-to-last element from the list, and would return None if the list doesn't contain enough elements.

Thoughts?

phated avatar Dec 17 '20 17:12 phated