Non-mutating array functions

I sometimes want non-mutating versions of push! and append! which copy their mutable inputs. Another thread asks about non-mutating versions of splice! and deleteat!.

Do we already have these somewhere? Can we add them to Base?

concatenation?

Yes, the non-mutating version of append! is simply vcat.

Here’s a non-mutating version of deleteat!:

julia> using Accessors: delete, @optic

julia> delete([3,4], @optic _[1]) == [4]
true
3 Likes
2 Likes

haha I forgot that’s my issue

4 Likes

It’s even nicer in practice:

x = [3, 4]
y = @delete x[1]

For push!, there’s of course @insert (:

y = @insert last(x) = 5
4 Likes