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)

1 Like

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")

?

defmodule Raw
  def check_param(%{left: nil} = head) do
  end

  def check_param(%{right: nil} = head) do
  end

  def check_param(_) do
  end
end

thanks exactly that