Enum.reduce for idiots

The answer above is very straightforward and I think should work pretty well!

If you do wanna go with reducing because the order matters, I think this should work:

Enum.reduce(lookup, [], fn %{key: key} = map, acc ->
  if Map.has_key?(params, key) do
    value = params[key]
    acc ++ [Map.put(map, :value, value)]
  else
    acc
  end
end)

Have not tested it, but I’d believe it will work

3 Likes