benonymus

benonymus

Hey,

I am trying to build a Plug pipeline, it’s pretty simple and works great, my function is the last in the chain and I am getting this warning when I am trying to run in an env with empty list as param.

I am getting the env
@unavailable_countries Application.get_env(:app, :unavailable_countries, [])
The warning is present if I explicitly set the env as a .

  defp is_available?(%{
         city: %{
           country: %{iso_code: iso_code}
         }
       })
       when iso_code in @unavailable_countries do
    false
  end

  defp is_available?(_), do: true

There is another warning for the iso_code that it is unused.

I know I could pass the list to the function and check, but I have other clauses as well with other lists, and then I couldn’t do it in the guard.

Is there a way to go around this?
I know that it will always yield the same result, I understand the warning.

Thanks

Showing Posts 1 to 8

benonymus

benonymus OP

Well I can put in [""] as the default for one.

fuelen

fuelen

Which warning?

benonymus

benonymus OP

Sorry I put it as the title:
This check/guard will always yield the same result

josevalim

josevalim

Creator of Elixir

Yes, the compiler is warning you that the guard will always fail, because no input will ever satisfy it.

benonymus

benonymus OP

So ideally should I write the function differently, or for dev environment passing just an empty string in as a possibility is fine?

hauleth

hauleth

You can conditionally add the first head:

if @unavailable_countries != [] do
  defp is_available?(%{
         city: %{
           country: %{iso_code: iso_code}
         }
       })
       when iso_code in @unavailable_countries do
    false
  end
end

  defp is_available?(_), do: true

Or simplify it to:

  defp is_available?(%{
         city: %{
           country: %{iso_code: iso_code}
         }
       }), do: iso_code not in @unavailable_countries

  defp is_available?(_), do: true
benonymus

benonymus OP

I will try the first thanks!
I think the simplified version wouldn’t work because I only want it to return if the item is in the list otherwise not, but this could return both true or false.

Edit: the check with the if around the function works, thanks!

hauleth

hauleth

I have fixed the “fixed” example to match your needs.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews