Skip to content

Commit

Permalink
Support negative index
Browse files Browse the repository at this point in the history
  • Loading branch information
vic committed Dec 20, 2016
1 parent 6b68d6b commit 4977c0b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/indifferent.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ defmodule Indifferent do
iex> [1, {2, 3}] |> Indifferent.path([1][0])
2
iex> [1, [2, 3]] |> Indifferent.path([1][-1])
3
iex> [9, %{"c" => {:ok, %{"e" => 4}}}] |> Indifferent.path(1.c["1"].e)
4
Expand Down
4 changes: 4 additions & 0 deletions lib/indifferent/path.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ defmodule Indifferent.Path do
expand(a, []) ++ expand(b, seen)
end

def expand(a = {:-, _, _}, seen) do
[a | seen]
end

def expand({a, _, nil}, seen) do
[a | seen]
end
Expand Down

0 comments on commit 4977c0b

Please sign in to comment.