Zesky665
Hi,
I need to somehow iterate over the entries in the map returned by Presence.list/1. This is what the map looks like on my end.
%{
"user:1" => %{
metas: [
%{initiator: 2, phx_ref: "tL574g0pn6w=", user_id: 1, username: "admin"}
]
},
"user:3" => %{
metas: [
%{initiator: 1, phx_ref: "7Qvfk3qEksE=", user_id: 3, username: "bob"}
]
}
}
What I need is to iterate over all of them and assign each with a initiator based on the order in which they appear in the map (ex: 1,2,3,4).
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #security










Showing Posts 1 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Nicd
You can iterate a map with
Enum.mapfor example but note that maps are not ordered so it is not guaranteed that you get any specific order for the users.Example:
Zesky665
So
Enum.map(presences, fn{k, v} -> {k, Enum.map(v, fn{k, v} -> {v.initiator} } )to iterate over theinitiatorvalue, but how do I update it? And btw, I don’t need any particular order just to have eachuser.initiatorbe a value from 1-5(no number repeating).Nicd
Unsure where you want the
initiatorvalue, in themetaslist or somewhere else? What do you want a single user map to look like?Zesky665
Just like the one in the first post but with the initiator value updated to be one of 1..5.
Nicd
This kind of sounds like an XY problem (I don’t understand why you need to do this), but here’s something:
Zesky665
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.
Zesky665
I’m not sure why but the
updated_mapwhen used inpush socket, "presence_state", Presence.list(socket)in place ofPresence.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)This is the result of
IO.inspect updated_mapNicd
It seems I made a mistake, I replaced the whole
metaslist with the first element in the list. The error is inupdated_val = put_in(val[:metas], meta). Instead of justmetathere, 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
metaslist 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.Zesky665
Thank you this works
Why do you think I asked this question here?