xshyne88
I have a goal to code generate the following module
defmodule C do
def first(%{company_id: company_id}, user}, do: do_first(company_id, user)
def first(%{sales_id: sales_id}, user}, do: do_first(sales_id, user)
#... etc
end
I’d like to create a macro potentially? Or even a function where I can give it a list of those atoms, and have it delegate those arguments to the second function
i.e
defmodule C do
use FirstMacro, [:company_id, :sales_id] #... could be a very long list
end
I keep writing macros but am unable to figure out how to code pattern match on a map macro the quoted ast for a map is something like {:%{}, , [key: value]} but I’m not able grab value like I would in defining a function so I can’t achieve my goal here, can someone point me in the right direction kindly ^^. Thanks for any help!
my attempt on the 100th iteration looks something like this
defmodule C do
defmacro first_list(list, user) do
quote bind_quoted: [list: list, user: user] do
Enum.map(list, fn x ->
def first(unquote({:%{}, [], []}), user),
do: do_first(:need_this_variable, user)
end)
end
end
end
But I know its all wrong ![]()
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
How do I tell Hologram not to escape HTML when substituting into templates?
{Textile.render(@product.long_description)}
escapes the HTM...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used?
I’ve got two Github accoun...
New
Other Trending Topics
The following two features were added to erlexec.
Container: exec:run_container/1: run a command in a container
You describe the contain...
New
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
Hi everyone :waving_hand:
I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
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
- #code-sync
- #discussion
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #elixirconf-us
- #blog-post
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #elixirconf-eu
- #processes
- #security
- #api
- #forms
- #performance










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
As
%{foo: foo}is syntactic sugar for%{:foo => foo}the following should work:But to be honest, how is
do_first/2supposed to know what kind of id you are passing in?xshyne88
I think the idea is to filter out the wrong ids using pattern matching, I thought about this but in my elixir noob head I thought that the %{key => value} syntax was sugar for the other %{key: value}
xshyne88
Thank you very much sir this is exactly what I needed.
NobbZ
Whats a wrong ID?
So how does
do_first/2know whether the1refers to asales_idor to acompany_id?xshyne88
In my particular app it doesn’t actually matter because all of our ID’s are global UUIDS. This is an Absinthe Batching function if that makes more sense. My resolvers are calling &SomeModule.first/3