Hi, I have been stuck into a problem, I have a list of nested maps from which I have to match it on base of role and then perform queries on that base
What I have done so far is:
to get roles:
roles = Enum.map(list, fn x ->
x |> Map.values() |> Enum.map(fn x -> x["role"] end)
end)
from which I get:
[["iso", "iso", nil], ["iso", "affiliate", "agent"]]
to iterate over each map:
Enum.each(roles, fn role ->
Enum.each(list, fn item ->
abc = Map.values(item)
Enum.filter(abc, fn item1 ->
case item1["role"] do
"iso" ->
query = ...
case query do
[] ->
....
_ ->
....
end
"agent" ->
query = ...
case query do
[] ->
....
_ ->
....
end
"affiliate" ->
query = ...
nil ->
IO.inspect("its nil")
_ ->
IO.inspect("Nothing works here")
end
end)
end)
end)
my list:
[
%{
"user_1_details" => %{
"dollar" => 2.0,
"from_wallet" => 108,
"percent" => "1.56",
"role" => "iso",
"wallet" => 4469
},
"user_2_details" => %{
"dollar" => 1.0,
"from_wallet" => 4469,
"percent" => "0.02",
"role" => "iso",
"wallet" => 5182
},
"user_3_details" => %{
"dollar" => 0.0,
"from_wallet" => 5182,
"percent" => "0.00",
"role" => nil,
"wallet" => nil
}
},
%{
"user_1_details" => %{
"dollar" => 1.0,
"from_wallet" => 108,
"percent" => "7.80",
"role" => "iso",
"wallet" => 4681
},
"user_2_details" => %{
"dollar" => 0.5,
"from_wallet" => 4681,
"percent" => "0.47",
"role" => "affiliate",
"wallet" => 6184
},
"user_3_details" => %{
"dollar" => 0.0,
"from_wallet" => 6184,
"percent" => "0.03",
"role" => "agent",
"wallet" => 7227
}
}
]
My Question is how can I get the value of first iteration in second iteration and second iteration value in third iteration, to be more clear I want to get the value of user_1_details
in user_2_details
and user_2_details
value in user_3_details
as I am not concerned with the keys here just the keys value that’s why I am just getting the values in my code above
Size of list can be 1, 2, or 3 i.e
[%{...}, %{...}] or [%{...}]
I have been knocking my head on this problem from almost a day but unable to find a way to do so!