Skip to content

Commit e068625

Browse files
author
José Valim
committed
Add integer guards around Enum.fetch/2
1 parent 00e8446 commit e068625

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/elixir/lib/enum.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,11 @@ defmodule Enum do
593593
594594
"""
595595
@spec fetch(t, integer) :: {:ok, element} | :error
596-
def fetch(collection, n) when is_list(collection) and n >= 0 do
596+
def fetch(collection, n) when is_list(collection) and is_integer(n) and n >= 0 do
597597
do_fetch(collection, n)
598598
end
599599

600-
def fetch(collection, n) when n >= 0 do
600+
def fetch(collection, n) when is_integer(n) and n >= 0 do
601601
res =
602602
Enumerable.reduce(collection, {:cont, 0}, fn(entry, acc) ->
603603
if acc == n do
@@ -613,7 +613,7 @@ defmodule Enum do
613613
end
614614
end
615615

616-
def fetch(collection, n) when n < 0 do
616+
def fetch(collection, n) when is_integer(n) and n < 0 do
617617
do_fetch(reverse(collection), abs(n + 1))
618618
end
619619

0 commit comments

Comments
 (0)