OffsetArrays.jl
OffsetArrays.jl copied to clipboard
WIP: Implement insert! and deleteat! for OffsetVectors
I consider this to be incomplete. I have not, for instance, thought carefully about whether I am referring to the axes
in the most appropriate way, but hey, all tests pass! Also, ideally the offset indices will be used in the exception message when the index is out of range; right now, the indices of the parent array are instead provided, and this can be confusing.
Just found https://github.com/JuliaArrays/OffsetArrays.jl/pull/55#issuecomment-438525109, which did not turn up in my earlier repository search. I still believe implementing insert!
and deleteat!
is valuable, but obviously it deserves some discussion first. I'll open an issue shortly to discuss the related question of whether to implement pushfirst!
and popfirst!
.
As you can tell from your readings, I'm mixed on this. If I had to take a stance, it would be "against by a hair." Here's why:
-
pushfirst!
really seems like it should grow in the "opposite direction", meaningfirstindex(a)
gets decremented rather thanlastindex(a)
being incremented -
insert!(a, firstindex(a), items)
should behave the same aspushfirst!
ifitems
is of length 1.
@timholy What about deleteat!
? I think that's a useful function and it's required for things like filter!
and would have been useful test cases for two PRs I recently wrote: https://github.com/JuliaLang/julia/pull/39528 and https://github.com/Vexatos/CircularArrays.jl/pull/12
We can have this if there's enough enthusiasm. I just think that the consensus has never been clear. Lots of people initially think "why isn't that implemented? I'll add it!" and then once the concerns are raised most eem to agree that it's not obvious we want it. If someone makes a sufficiently clear case and is willing to document the behavior carefully, we can do things like this. But the principle of "do no harm" holds me back from adding this until someone really pushes a strong argument.