Consider the (smelly, non-idiomatic) function, as shown below:
def update_2d(array, inds, val) do [first_coord, second_coord] = inds new_arr = List.update_at(array, second_coord, fn(y) -> List.update_at(Enum.at(array, second_coord), first_coord, fn(x) -> val end) end) end
This function will accept a list of lists, a list of two indices, and a value to be inserted into the list of lists at the location indicated by the indices.
As a first step to making this bigger than Elixir-ey, I'm starting to lay the pipe:
array |> Enum.at(second_coord) |> List.update_at(first_coord, fn(x) -> val end)
I like it most, but how can I pass this output to the anonymous function of the last call to List.update_at ? . I can put it in the original call, but it seems like a failure:
List.update_at(array, second_coord, fn(y) -> array |> Enum.at(second_coord) |> List.update_at(first_coord, fn(x) -> val end) end)
source share