chan11347

chan11347

Print all data out

todo_server = [
%{date: ~D[2020-05-19], id: 1 ,time: ~T[16:52:00], title: "Shopping"},
%{date: ~D[2020-05-19], id: 2 ,time: ~T[16:52:00], title: "thinking"},
%{date: ~D[2020-05-20], id: 3 ,time: ~T[16:52:00], title: "Drinking"},
%{date: ~D[2020-05-20], id: 4 ,time: ~T[16:53:00], title: "swimming"}
]

i have 4 different value, so i can use

def time_check(todo_server, time) do
    GenServer.call(todo_server, {:time_check, time})
  end

i have a function can print out the whole result with the time i asked for
Todo.Server.time_check(todo_server, ~T[16:52:00])
return

[
%{date: ~D[2020-05-19], id: 1 ,time: ~T[16:52:00], title: "Shopping"},
%{date: ~D[2020-05-19], id: 2 ,time: ~T[16:52:00], title: "thinking"},
%{date: ~D[2020-05-20], id: 3 ,time: ~T[16:52:00], title: "Drinking"}
]

but how to print our the whole todo_server? by

def show_all(x) do
    IO.inspect(x)
  end

?

Most Liked

lucaong

lucaong

So you want to see all values in the todo_list part of the GenServer state (that’s different from “the value of todo_server”, as todo_server in your time_check function is the pid or name of a GenServer process).

Here is the code from your previous message:

def handle_call({:show_all}, _, {name, todo_list}) do
  {:reply, Todo.List.show_all(todo_list), {name, todo_list}}
end

You are matching on the message {:show_all}, so you need to issue the following call: GenServer.call(todo_server, {:show_all}).

Note that there are a couple of more things you could improve, not related to the main question though:

  1. Your message is a tuple of a single element, {:show_all}. It’s not really necessary to wrap the message in a tuple, if it’s made of a single value: you could just send directly the atom :show_all instead. Of course, if you change this, the message that you send in GenServer.call should match the one that you pattern match in handle_call.

  2. Instead of printing the list with IO.inspect, you could just return it, and in case let the caller print it.

kip

kip

ex_cldr Core Team

As @lucaong pointed out, the message you send must have a matching function head. In this cas you are sending the message :show_all but you are only expecting a message {:show_all}. They are not the same.

For this class of error the messages are pretty clear I think so its good to get comfortable with reading function clause errors.

Where Next?

Popular in Questions Top

shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
nsuchy
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
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
makeitrein
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
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
alice
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
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
joeerl
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

Other popular topics Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement