MUSTDOS

MUSTDOS

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{}} ] }
]

Showing Posts 1 to 5

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.

al2o3cr

al2o3cr

(NOTE: spruced up the formatting of your code example using triple-backticks ```)

I don’t personally see a huge difference between adding a stream by writing:

  {:stream, [{:whatever, %Whatever{}}]},

and

  |> stream(:whatever, %Whatever{})

Your post mentions “along with their parentheses”, but the former definitely seems to have more bracketry than the latter.

MUSTDOS

MUSTDOS OP

initializer_list = [
 {:stream, [
            {:whatever1, %Whatever1{}},
            {:whatever2, %Whatever2{}},
            {:whatever3, %Whatever3{}}
           ]
 },
 
 {:assign, [
            {:whatever4, %Whatever4{}},
            {:whatever5, %Whatever5{}},
            {:whatever6, %Whatever6{}}
           ]
 }
]

VS

socket
 |> stream(:whatever1, %Whatever1{})
 |> stream(:whatever2, %Whatever2{})
 |> stream(:whatever3, %Whatever3{})
 |> assigns(:whatever, %Whatever{})
 |> assigns(:whatever, %Whatever{})
 |> assigns(:whatever, %Whatever{})
(or)
|>assigns(fn %{struct_of_whatever: struct_of_whatever} -> %{whatever: struct_of_whatever} end)

I just felt easier for multiple copy and pastes for bigger pages.

MUSTDOS

MUSTDOS OP

Sorry for multiple repeated posts; it just gave me error occurred or something for clicking reply until I refreshed

kevinschweikert

kevinschweikert

all good! i’ve cleaned up the previous posts

— All posts loaded —

Where Next? Top

Trending in Proposals: Ideas Top

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
aseigo
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews