shahryarjb
Guard `in` list doesn't work in function's parameters
Hello , I have 3 fn which create and check list, but it does not work for me .
for example :
list creator :
defp string_to_array(string) when is_binary(string) do
String.split(string, [" ", ","])
end
and check fn :
defp merge_db_plug_category(query, group_acl) when group_acl in ["admin"] do
IO.puts "1"
IO.inspect group_acl
end
defp merge_db_plug_category(query, group_acl) do
IO.puts "2"
IO.inspect group_acl
end
I get ["admin"] list when I send and inspect group_acl, but always merge_db_plug_category(query, group_acl) works , why doesn’t when group_acl in ["admin"] work for me ?
how can I check list in function parameters ?
Most Liked
NobbZ
NobbZ
Set functions aren’t expressable in a guard safe way you need to move the check into the body of the function or use recursion over the list and build a map of valid entries/roles where you then can again pattern match on.
3
LostKobrakai
Afaik you cannot do that in guards or via pattern matching.
How about
Enum.reduce(group_acl, query, fn
"admin", query ->
IO.puts "1"
query
_, query ->
IO.puts "2"
query
end)
2
Last Post!
OvermindDL1
Well they are more easily done so if they use a map instead of a list, especially with the new OTP 21 features. ![]()
2
Popular in Questions
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
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
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
Other popular topics
Hi!
In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir?
Searched the docs for ip address and the web, no good results.
Thanks!
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Hello everyone,
Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
Hello all!
I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #hex
- #security









