grain
grain copied to clipboard
Stdlib: Negative indexing discussion
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?