Skip to content

Commit adecd83

Browse files
committed
raise ArgumentError for invalid Enum.count_until
As a follow up to elixir-lang#15027, provide a nicer error message when invoking `Enum.count_until` with an invalid limit
1 parent fc747ff commit adecd83

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

lib/elixir/lib/enum.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,10 @@ defmodule Enum do
780780
end
781781
end
782782

783+
def count_until(_enumerable, _limit) do
784+
raise ArgumentError, "Enum.count_until/2 only accepts limits greater than 0"
785+
end
786+
783787
@doc """
784788
Counts the elements in the enumerable for which `fun` returns a truthy value, stopping at `limit`.
785789
@@ -801,6 +805,10 @@ defmodule Enum do
801805
end
802806
end
803807

808+
def count_until(_enumerable, _fun, _limit) do
809+
raise ArgumentError, "Enum.count_until/3 only accepts limits greater than 0"
810+
end
811+
804812
@doc """
805813
Enumerates the `enumerable`, returning a list where all consecutive
806814
duplicate elements are collapsed to a single element.

0 commit comments

Comments
 (0)