Hi!
I have been dealing with some problem where I have a nested list, I want to keep the nested structure, but if the list is a two elements list, then i want to apply a custom function (I’m dealing with multypolygon coordinates and want to apply some transform to the coordinates’ system)
So far, I came up with something using recursion:
defmodule NiceModule do
def apply_function(nested_list) do
update_in(nested_list, [Access.all()], fn item ->
case item do
[x, y] when is_number(x) and is_number(y) -> fun_fun(x, y)
sublist when is_list(sublist) -> apply_function(sublist)
other -> other
end
end)
end
def fun_fun(x,y) do
{a,b} ={ x+3 , y+2}
[a,b]
end
end
aa = [
[2, 5.0 , [ 1 , 1 ]],
[[13.0, 17.0], [25.0, 0.0], [0, 0]] ,
[ 2 ,2 ]
]
NiceModule.apply_function(aa)
Which I think works, but I’m wondering if I’m doing something anti-elixir or if there is a better way (needless to say, I’m new)
Thanks for your time and answers ![]()






















