Skip to content

Commit 61fb890

Browse files
author
José Valim
committed
Merge pull request #1511 from guilleiguaran/with_index
Move definition of with_index below
2 parents 7bb592c + d1e26ea commit 61fb890

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

lib/elixir/lib/enum.ex

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,23 +1057,6 @@ defmodule Enum do
10571057
end
10581058
end
10591059

1060-
@doc """
1061-
Returns the collection with each element wrapped in a tuple
1062-
along side its index.
1063-
1064-
## Examples
1065-
1066-
iex> Enum.with_index [1,2,3]
1067-
[{1,0},{2,1},{3,2}]
1068-
1069-
"""
1070-
@spec with_index(t) :: list({ element, non_neg_integer })
1071-
def with_index(collection) do
1072-
map_reduce(collection, 0, fn x, acc ->
1073-
{ { x, acc }, acc + 1 }
1074-
end) |> elem(0)
1075-
end
1076-
10771060
@doc """
10781061
Returns the maximum value.
10791062
Raises empty error in case the collection is empty.
@@ -1192,6 +1175,23 @@ defmodule Enum do
11921175
end
11931176
end
11941177

1178+
@doc """
1179+
Returns the collection with each element wrapped in a tuple
1180+
along side its index.
1181+
1182+
## Examples
1183+
1184+
iex> Enum.with_index [1,2,3]
1185+
[{1,0},{2,1},{3,2}]
1186+
1187+
"""
1188+
@spec with_index(t) :: list({ element, non_neg_integer })
1189+
def with_index(collection) do
1190+
map_reduce(collection, 0, fn x, acc ->
1191+
{ { x, acc }, acc + 1 }
1192+
end) |> elem(0)
1193+
end
1194+
11951195
## Helpers
11961196

11971197
defp iterate_and_count(collection, count) do

0 commit comments

Comments
 (0)