Skip to content

Commit

Permalink
Move definition of with_index below
Browse files Browse the repository at this point in the history
Right now is defined in the middle of two definitions of max function.
  • Loading branch information
guilleiguaran committed Jul 28, 2013
1 parent cca4ac9 commit d1e26ea
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lib/elixir/lib/enum.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1058,23 +1058,6 @@ defmodule Enum do
end
end

@doc """
Returns the collection with each element wrapped in a tuple
along side its index.
## Examples
iex> Enum.with_index [1,2,3]
[{1,0},{2,1},{3,2}]
"""
@spec with_index(t) :: list({ element, non_neg_integer })
def with_index(collection) do
map_reduce(collection, 0, fn x, acc ->
{ { x, acc }, acc + 1 }
end) |> elem(0)
end

@doc """
Returns the maximum value.
Raises empty error in case the collection is empty.
Expand Down Expand Up @@ -1193,6 +1176,23 @@ defmodule Enum do
end
end

@doc """
Returns the collection with each element wrapped in a tuple
along side its index.
## Examples
iex> Enum.with_index [1,2,3]
[{1,0},{2,1},{3,2}]
"""
@spec with_index(t) :: list({ element, non_neg_integer })
def with_index(collection) do
map_reduce(collection, 0, fn x, acc ->
{ { x, acc }, acc + 1 }
end) |> elem(0)
end

## Helpers

defp iterate_and_count(collection, count) do
Expand Down

0 comments on commit d1e26ea

Please sign in to comment.