Closed
Description
Currently, Data.String.CodeUnits.slice
returns Nothing
on slices from the final index to the final index, e.g.
slice 4 4 "test" == Nothing
I find this behavior to be undesirable. It:
- Means that "out of bounds" has different meanings for the two bounds, which I personally find to be unintuitive.
- Nullifies the invarant that for each
i
from0
throughlength s
, we haves == slice 0 i s <> slice i (length s)
. Instead, this only holds up tolength s - 1
.
Motivating example: I was dealing with string containing two parts separated by a delimiter, like prefix:::suffix
. I had a function to separate the two parts, getParts :: String -> Maybe (String /\ String)
, which was implemented via indexOf
and split
. With the current split
implementation, this function has that getParts ":::suffix" == Just ("" /\ "suffix")
but getParts "prefix:::" == Nothing
, which is surprising.
Happy to make an MR if it's decided that this is reasonable. I suppose it's technically a reverse-incompatible change, though.