DEV Community

loading...

Discussion on: My First Week With Elixir As A Rubyist

Collapse
fidr profile image
Robin

You can also match on equality by re-using the same param name in the function definition:

defmodule Example do
  def any?([], _a), do: false
  def any?([a | _tail], a), do: true
  def any?([_head | tail], a), do: any?(tail, a)
end
Collapse
ssolo112 profile image
Steven Solomon Author

I really dig the pattern for head being equal to the element you are looking for.

Forem Open with the Forem app