MUSTDOS

MUSTDOS

Multi assign/stream

Hello all!

assign(socket, :name, “Elixir”)

Why can’t we have assign/stream take a group of atoms and maps/structs as a default to reduce spamming assign/stream along with their parentheses?

I know this isn’t a perfect example of code but here’s what I cooked up but it returns a list of assigns/streams instead finalizing them

def socket_initializer(socket,initializer_list) do
  socket = Enum.map(initializer_list, fn {key,value} ->
    case key do
      :stream -> 
        Enum.map(value, fn {stream_name, stream_value} -> 
         IO.inspect stream(socket, stream_name, stream_value)
        end)

      :assign ->
        Enum.map(value, fn {assign_name, assign_value} ->
          IO.inspect assign(socket, assign_name, assign_value)
        end)

      _ ->
        IO.puts(to_string(key) <> " is not a valid initalizer")
    end
  end)
end

initializer_list = [
  { :assign , [ {:search, %Worker{}}, {:active_account_tuple , Operations.status_tuple_registration()} ] },
  { :stream , [ {:workers , %Worker{}} ] }
]

Most Liked

rhcarvalho

rhcarvalho

stream/4 works on a single stream, but assign/2 can assign multiple values at once.

The one you were referring to is assign/3 which works on a single item.

kevinschweikert

kevinschweikert

all good! i’ve cleaned up the previous posts

Where Next?

Popular in Proposals: Ideas Top

derekkraan
I have been using a multi-endpoint setup in my app, just because I think it makes the most sense for a multi-subdomain app. This worked w...
New
cevado
IEx is a very powerfull shell and it would be awesome to have all this power integrated inside a code editor. Clojure enables something l...
New
mortenlund
Hi! I would like to suggest a new callback in the lifecycle of the Live Component which is unmount. Sometimes it is nice to be able to ...
New
pelopo
Hi, Oficial docs got this wonderful feature to download the ePub version that we can chuck to our kindles and read it. Now we are in the...
New
New
dogweather
Hi Phoenix community! First off, huge thanks for an amazing framework - Phoenix has been a joy to work with. I have a small UX suggestio...
New
moacirbishopcamata
Good morning to the Elixir team. Please excuse me if I’m commenting in the wrong place; please indicate where I should discuss this. I ...
New

Other popular topics Top

jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31525 112
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
New

We're in Beta

About us Mission Statement