samullen
In his excellent talk, “Architecting Flow in Elixir”, René Föhring discussed three different approaches to passing data through a process: pipelines, the with macro, and token passing (ex. Plug and Ecto.Changeset).
With regard to the with macro he said it’s “made for those complex scenarios…where the APIs offered functions do not deliver exactly what we need.” I take it to mean that the with macro is better used with function calls against APIs existing outside of a given module or set of modules, (e.g. libraries, services, etc.)
I’m curious to know what criteria the community uses for determining which approach to use and when.
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
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
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
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
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #elixirconf-us
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 4- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
To me those 3 things are actually two. I see the token approach as a means to clean up complex code with spread out dependencies/inputs into code, which can be pipelined very well.
For with vs. pipelines I have the soft rule of the pure functional core using pipelines and with being used at the outside where you not only have to deal with data, but also side-effects.
hauleth
I see it mostly as a solution for “gathering” errors. So if, for example, you need to return more than 1 error (like in Ecto) then token passing is better as it makes accumulation simpler.
peerreynders
…and because context was already taken by Phoenix
A paper (PDF) describes the
Context Object - A Design Pattern for Efficient Information Sharing across Multiple System Layers
which was submitted for
The 12th Pattern Languages of Programs (PLoP) 2005
conference
So calling it a (processing) context (structure) instead of a token is entirely justified (and because of bounded context I call it a Phoenix context anyway).
The majority of the talk is about designing/implementing a context-driven processing “pipeline”.
Architecting Flow in Elixir:
withor|>for Architecting Flow in Elixir Programs?Better Control Flow Using the “with” Macro
Robust Data Processing Pipeline with Elixir and Flow - Laszlo Bacsi - ElixirConf EU 2018 (Slides)
You’re typically designing around a context type when an earlier stage is creating information which is used by a later stage while intermediate stages completely ignore that information. If your function’s first parameter is a tuple or map that contains information that is returned as is and is never inspected then that first parameter/return value may be a context type.
Having complete control over your own function signatures it is quite easy to implement them to accept and return the context type so that these functions just work with the pipe operator (
|>).However that also couples those functions to the context type - so it’s not something one does to functions that are reused in different situations as general functions don’t make allowances for accepting and passing “context information”.
So
with/1is often used when these more general/reusable functions are stitched into a flow (typically for errors, though you can flow “out-of-band” data inside tuples around functions that don’t use it - personally I think “adaptor functions” are clearer).samullen
Great. Thanks for the feedback and the reference material. This helps a lot.