xoron
Elixir function call on pattern match
i need to call function and function get map in argument and i also extract one property from
map to use in guard and i also need other property on map in function
i want my function to take only single argument and not expand all property except the one which
i use in guard
defmodule Raw do
@doc """
i also need head in check_param function
for this i have to expand my argument to check params like check_params(%{left: left, right: right})
but if head have 5 properties than its not look good to mention all
And check guard on only one property left or right
Other solution is to pass head as second argument check_param(%{left: left},head)
i want to know any shortcut or good solution for this
because i think i miss something there must be way
in elixir to handle it better
"""
def check_param(%{left: left}, head) when left == nil do
IO.puts("left")
# IO.puts(head)
end
def check_param(%{right: right}, head) when right == nil do
IO.puts("right")
# IO.puts(head)
end
def check_param(_) do
IO.puts("true")
end
end
head = %{left: 10, right: nil}
Raw.check_param(head, head)
First Post!
hauleth
You mean you want something like:
def check_param(%{left: nil} = head), do: IO.puts("left")
def check_param(%{right: nil} = head), do: IO.puts("right")
?
Popular in Questions
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database.
Dep...
New
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
Hey,
I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project.
Baby step #1 is extracting the number ...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Hi,
I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
Other popular topics
What is the proper way to load a module from a file in to IEX?
In the python world, doing something like this pretty standard:
from ....
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
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
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set?
Thanks.
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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 have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New







