Skip to content

Instantly share code, notes, and snippets.

@SadPandaBear
Last active October 26, 2017 09:56
Show Gist options
  • Save SadPandaBear/97613059c8c1475f56e11f80178e7657 to your computer and use it in GitHub Desktop.
Save SadPandaBear/97613059c8c1475f56e11f80178e7657 to your computer and use it in GitHub Desktop.
defmodule Utils do
def value_at(list, 0), do: List.first(list)
def value_at(list, index) when index > length(list), do: raise "Index(#{index}) out of bounds on List"
def value_at(list, index) when index > 0 do
[_ | tail] = list
value_at(tail, index - 1)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment