I want to use functions like
insert! without mutating whatever they work on.
Concretely, I have vectors where I replace two neighboring values by their sum which I thought I’d achieve with
vec = [1:10...] indices = [3;4] newvec = deleteat!(insert!(vec,max(indices)+1,sum(vec[indices])),indices);
but I still need the original vector.
If someone can tell me how to do it more readable, I’d appreciate that too.
Anyway, I guess a solution would be to use
newvec = copy(vec) newvec = deleteat!(insert!(newvec,max(indices)+1,sum(newvec[indices])),indices);
but that makes my code a lot less readable since I’m mapping this operation over an iterator of dictionary keys so the whole thing turns into a monster like
which doesn’t even work because I can’t copy KeyIterators and I’d rather not collect all keys beforehand.
Any ideas? I’m a bit irritated by all the functions that aren’t available side-effect free such as
insert!, etc. but maybe I’m just missing something.