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

AHBruns
Rethinking phx-no-feedback So, I won’t go into how phx-no-feedback works in detail, but the tl;dr is that it lets you conditionally add a...
New
altdsoy
Hi there :wave:, I hope everyone is doing well… Tl;Dr: Is there a use case to have Heroicons from an actual hex.pm package instead of G...
New
dibok
Hi, I’m trying to use phoenix.js in my Qt QML project which has it’s own buildin JavaScript engine. Problem is that (what I googled so f...
New
Flo0807
Hello everyone! Phoenix LiveView v0.18 introduced the special attributes :let, :for and :if. In addition to the :if special attribute, I...
New
dvartic
Would there be interest to implement a link/1 that gives to option to operate on other events? So I implemented a simple link/1 function...
New
MatinDevs
Currently, there are ongoing discussions about enhancing Phoenix LiveView, particularly focusing on improving performance and user experi...
New
woylie
We are seeing a lot of warning logs like this: navigate event to "https://someurl" failed because you are redirecting across live_sessio...
New

Other popular topics Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement