Hi, I have this double condition if foo && bar do something and all the other cases basically don’t interest me. both foo and bar are assigns in a liveview socket, and I believe there’s a nicer, more elixir style way, of writing my function. I am thinking of some cond with pattern matching, but not sure how to put together the syntax - I am basically stuck at the very first line of the block :-o Can you please give me a hint? Thank you
# 1. check whether we have socket.assign.user
# 2. check if all todos are true
IO.inspect socket.assigns
socket =
if (socket.assigns.user && list_completed?(socket.assigns.list_id)) do
email = socket.assigns.user.email
list_url = "https://organizer.gigalixirapp.com/#{list_id}"
IO.puts "All tasks complete!"
socket =
socket
|> put_flash(:info, "All tasks complete! Sending notification to #{email}...")
Task.Supervisor.start_child(Organizer.TaskSupervisor, fn ->
IO.puts "Sending to #{email} from within a Task"
Organizer.Mailer.send_completion_notification(email, list_url)
end)
socket
else
IO.puts "Nope, either no user, or list not complete yet..."
socket
end
...
defp list_completed?(list_id) do
Lists.list_todos(list_id)
|> Enum.all?(&(&1.done)) # checks if all true https://hexdocs.pm/elixir/Enum.html#all?/2
end


















