Last active
October 26, 2017 09:56
-
-
Save SadPandaBear/97613059c8c1475f56e11f80178e7657 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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