Why is there no update method for Tuple

I find there is update method for List but not for Tuple. Because this is not efficiency?

There is the Tuple.append function (docs).

I think the main idea behind tuples is for them to generally be fixed length and not often changed in this way.

There’s not such a thing in elixir, but you can always use the erlang’s setelement/3

http://erlang.org/doc/man/erlang.html#setelement-3

iex(11)> :erlang.setelement(2, {1,2,3}, "foo")
{1, "foo", 3}
2 Likes

Thanks, will lookup erlang next time :slight_smile:

1 Like

Sure there is, it’s called put_elem/3:

iex(1)> put_elem({:foo, :bar, :baz}, 1, :qux)
{:foo, :qux, :baz}
12 Likes

Thanks to remind me I always keep relying on erlang libs…

2 Likes

Is there an update function for Tuples similar to Kernel’s update_in, which accepts an update function?

You can use Access.elem with all the *_in functions