Skip to content

Instantly share code, notes, and snippets.

@boxxxie
Created October 11, 2016 15:08
Show Gist options
  • Save boxxxie/ed8a0b94d684b77a6c99acec5b11cc75 to your computer and use it in GitHub Desktop.
Save boxxxie/ed8a0b94d684b77a6c99acec5b11cc75 to your computer and use it in GitHub Desktop.
@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