I have this value as
%{is_public: true, discoverable: true}
This could be anything not specifically is_public and discoverable, but all the keys which will come in above Map will be available in a struct of a camera.
%Camera{
__meta__: #Ecto.Schema.Metadata<:loaded, "cameras">,
created_at: #DateTime<2017-08-25 14:13:55.524563Z>,
discoverable: true,
exid: "everc-fhlcr",
id: 12769,
is_online: true,
is_online_email_owner_notification: false,
is_public: true,
last_online_at: #DateTime<2019-05-14 11:10:45.000000Z>,
last_polled_at: #DateTime<2019-05-14 11:10:47.000000Z>,
}
I want to get the values from the Camera struct on the basis of Map i.e
iex(4)> changes = %{is_public: true, discoverable: true} |> Map.keys
[:discoverable, :is_public]
I can get the keys from changes map with Map.keys
But I am not sure about how to map values from Camera struct.
from above Camera Struct and changes map, I want to get this type of Map.
%{
is_public: true,
discoverable: true
}
it seems like the same above map but it depends on Camera Struct values, they both can be false or true , same as id, exid, is_online.
If I do this
Enum.map(changed_keys, fn(key) ->
key: Map.get(camera, key)
end)
This still doesn't work, any help would be appreciable. thanks
I just want to make a map with anonymous keys in changes Map, and then get their values from Camera Struct and create a new map with those values and anonymouse keys.