Recursive function to iterate over a list

The recursive thinking:

  1. If the list is empty, then the thing you want to find is definitely not in that list.
  2. If the first element is what you want to find, then you found it.
  3. If the first element is not what you want to find, then find that thing in the rest of the list (which is still a list, could be empty, though)

So the code is

def exist?([], _item), do: false

def exist?([item | _tail], item), do: true

def exist?([_something_else | tail], item), do: exist?(tail, item)