Created
October 11, 2016 15:08
-
-
Save boxxxie/ed8a0b94d684b77a6c99acec5b11cc75 to your computer and use it in GitHub Desktop.
This file contains 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
@doc """ | |
This preforms an index lookup for data structures (tuple/list/Map) | |
""" | |
def nth(index) do | |
fn | |
tuple when is_tuple(tuple) -> | |
tuple |> elem(index) | |
enum -> | |
enum |> Enum.at(index) | |
end | |
end | |
def nth(obj, index), do: nth(index).(obj) | |
def first(list), do: nth(0).(list) | |
def second(list), do: nth(1).(list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment