You can iterate a map with Enum.map for example but note that maps are not ordered so it is not guaranteed that you get any specific order for the users.
So Enum.map(presences, fn{k, v} -> {k, Enum.map(v, fn{k, v} -> {v.initiator} } ) to iterate over the initiator value, but how do I update it? And btw, I don’t need any particular order just to have each user.initiator be a value from 1-5(no number repeating).
I need it for a webrtc signaling thing I’m developing. What I need precisely is a list of users with scaling numbers assigned to them in order to figure out which peers are supposed to initiate connections with which peers.
I’m not sure why but the updated_map when used in push socket, "presence_state", Presence.list(socket) in place of Presence.list(socket) causes in error in the front end.
Edit 1:
I figured out where the issue was. The function you wrote changes the metas from a list to a map:
This is the result of IO.inspect Presence.list(socket)
It seems I made a mistake, I replaced the whole metas list with the first element in the list. The error is in updated_val = put_in(val[:metas], meta). Instead of just meta there, we should use [meta | tl(val.metas)] so it is a proper list again.
Note that I am assuming it is the first element in the metas list that you need to change. If it’s some other element, this may not work. Which makes me think there is some better API for this than modifying the structures directly.