Skip to content

Commit f581049

Browse files
sabiwarajosevalim
authored andcommitted
Fix bug in Enum.drop/2 (#12040)
1 parent 6c06817 commit f581049

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/elixir/lib/enum.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4491,7 +4491,7 @@ defmodule Enum do
44914491

44924492
{count,
44934493
fn start, amount, _step ->
4494-
list |> :lists.reverse() |> slice_exact(start, amount, 1, 1)
4494+
list |> :lists.reverse() |> slice_exact(start, amount, 1, count)
44954495
end}
44964496
end
44974497
end

lib/elixir/test/elixir/enum_test.exs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,20 @@ defmodule EnumTest do
265265
end
266266
end
267267

268+
test "drop/2 with streams" do
269+
drop_stream = fn list, count -> list |> Stream.map(& &1) |> Enum.drop(count) end
270+
271+
assert drop_stream.([1, 2, 3], 0) == [1, 2, 3]
272+
assert drop_stream.([1, 2, 3], 1) == [2, 3]
273+
assert drop_stream.([1, 2, 3], 2) == [3]
274+
assert drop_stream.([1, 2, 3], 3) == []
275+
assert drop_stream.([1, 2, 3], 4) == []
276+
assert drop_stream.([1, 2, 3], -1) == [1, 2]
277+
assert drop_stream.([1, 2, 3], -2) == [1]
278+
assert drop_stream.([1, 2, 3], -4) == []
279+
assert drop_stream.([], 3) == []
280+
end
281+
268282
test "drop_every/2" do
269283
assert Enum.drop_every([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2) == [2, 4, 6, 8, 10]
270284
assert Enum.drop_every([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3) == [2, 3, 5, 6, 8, 9]

0 commit comments

Comments
 (0)