Is it possible to choose where the pipe output is inserted into Elixir function args?
You can simply bind to a variable to capture your first result and then replace it in the second List.update_at/3
call
def update_2d(array, inds = [first_coord, second_coord], val) do
updated =
array
|> Enum.at(second_coord)
|> List.update_at(first_coord, fn(x) -> val end)
List.update_at(array, second_coord, fn(x) -> updated end)
end
You can also use the capture operator to do this:
def update_2d(array, inds = [first_coord, second_coord], val), do:
array
|> Enum.at(second_coord)
|> List.update_at(first_coord, fn(x) -> val end)
|> (&(List.update_at(array, second_coord, fn(y) -> &1 end))).()
I find using a variable much more readable, but the option is there.