Skip to content

Commit 906a69a

Browse files
committed
Delegate to :lists.suffix/2
1 parent 3d90896 commit 906a69a

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

lib/elixir/lib/list.ex

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -933,17 +933,7 @@ defmodule List do
933933
@spec ends_with?(list, []) :: true
934934
@spec ends_with?([], nonempty_list) :: false
935935
def ends_with?(list, suffix) do
936-
case ends_with_offset(list, suffix) do
937-
nil -> false
938-
n -> :lists.nthtail(n, list) === suffix
939-
end
940-
end
941-
942-
defp ends_with_offset([], [_ | _]), do: nil
943-
defp ends_with_offset(rest, []), do: length(rest)
944-
945-
defp ends_with_offset([_ | tail], [_ | suffix_tail]) do
946-
ends_with_offset(tail, suffix_tail)
936+
:lists.suffix(suffix, list)
947937
end
948938

949939
@doc """

lib/elixir/test/elixir/list_test.exs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,11 @@ defmodule ListTest do
310310
end
311311

312312
test "only accepts proper lists" do
313-
message = "no function clause matching in List.ends_with_offset/2"
314-
315-
assert_raise FunctionClauseError, message, fn ->
313+
assert_raise ArgumentError, ~r/not a list/, fn ->
316314
List.ends_with?([1 | 2], [1 | 2])
317315
end
318316

319-
message = "no function clause matching in List.ends_with_offset/2"
320-
321-
assert_raise FunctionClauseError, message, fn ->
317+
assert_raise ArgumentError, ~r/not a list/, fn ->
322318
List.ends_with?([1, 2], 1)
323319
end
324320
end

0 commit comments

Comments
 (0)