stdlib
stdlib copied to clipboard
Argument labels for bit_array.slice and string.slice are inconsistent
// bit_array
pub fn slice(
from string: BitArray,
at position: Int,
take length: Int,
) -> Result(BitArray, Nil)
// string
pub fn slice(
from string: String,
at_index idx: Int,
length len: Int,
) -> String
It would be nice if they had the same labels. I tried looking for more functions like that, but I didn't find anything else.
This could be upgraded with optional args, but without them, this is a breaking change. However stdlib is not yet 1.0 so this might still be doable, I hope.
What should we make them?
Personally I like the bit_array
ones much better.
Now I noticed the return type is different too, that's unfortunate :(
Also, string.slice
lets you use negative indices to slice starting at some offset from the end of the string, while bit_array.slice
doesn't. Maybe both could accept that?
It's not possible as you can't negatively traverse a string, graphemes are not of constant size.
Thanks for the input @lpil . I think my reply might have been a bit confusing (sorry!), so just to clarify: I meant being able to pass a negative number to the "position" argument in bit_array.slice for convenience, so slicing at a position of -4 with a length of 4 would give you the 4 last bytes, for example. Mostly because string.slice seems to allow that. Does this sound like a good idea, or should users just use byte_size(bit array) anyway?
Oh! If strings support it then we should support it for bit arrays too