Cannot pattern-match a key in struct using `in`

Avoid duplicating the branch though. You can do something like that:

    response = {:ok, %{hidden: true, other: "field"}}

    case response do
      {:ok, result} when result == [] when :erlang.map_get(:hidden, result) == true ->
        :do_something

      _ ->
        :do_something_else
    end

Edit: reading the first and last posts of this topic I would believe Elixir had a map_get function but it does not seem so.

1 Like