Skip to content

Commit fe2425a

Browse files
authored
Soft-deprecate List.zip/1 in favor of Enum.zip/1 (#13767)
1 parent cc70737 commit fe2425a

File tree

3 files changed

+6
-54
lines changed

3 files changed

+6
-54
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ This release no longer supports WERL (a graphical user interface for the Erlang
2929

3030
### 3. Soft deprecations (no warnings emitted)
3131

32+
#### Elixir
33+
34+
* [List] `List.zip/1` is deprecated in favor of `Enum.zip/1`
35+
3236
### 4. Hard deprecations
3337

3438
#### EEx

lib/elixir/lib/list.ex

+2-47
Original file line numberDiff line numberDiff line change
@@ -633,25 +633,9 @@ defmodule List do
633633
[other]
634634
end
635635

636-
@doc """
637-
Zips corresponding elements from each list in `list_of_lists`.
638-
639-
The zipping finishes as soon as any list terminates.
640-
641-
## Examples
642-
643-
iex> List.zip([[1, 2], [3, 4], [5, 6]])
644-
[{1, 3, 5}, {2, 4, 6}]
645-
646-
iex> List.zip([[1, 2], [3], [5, 6]])
647-
[{1, 3, 5}]
648-
649-
"""
650-
@spec zip([list]) :: [tuple]
651-
def zip([]), do: []
652-
636+
@doc deprecated: "Use Enum.zip/1 instead"
653637
def zip(list_of_lists) when is_list(list_of_lists) do
654-
do_zip(list_of_lists, [])
638+
Enum.zip(list_of_lists)
655639
end
656640

657641
@doc ~S"""
@@ -1372,33 +1356,4 @@ defmodule List do
13721356
defp do_pop_at([head | tail], index, default, acc) do
13731357
do_pop_at(tail, index - 1, default, [head | acc])
13741358
end
1375-
1376-
# zip
1377-
1378-
defp do_zip(list, acc) do
1379-
converter = fn x, acc -> do_zip_each(to_list(x), acc) end
1380-
1381-
case :lists.mapfoldl(converter, [], list) do
1382-
{_, nil} ->
1383-
:lists.reverse(acc)
1384-
1385-
{mlist, heads} ->
1386-
do_zip(mlist, [to_tuple(:lists.reverse(heads)) | acc])
1387-
end
1388-
end
1389-
1390-
defp do_zip_each(_, nil) do
1391-
{nil, nil}
1392-
end
1393-
1394-
defp do_zip_each([head | tail], acc) do
1395-
{tail, [head | acc]}
1396-
end
1397-
1398-
defp do_zip_each([], _) do
1399-
{nil, nil}
1400-
end
1401-
1402-
defp to_list(tuple) when is_tuple(tuple), do: Tuple.to_list(tuple)
1403-
defp to_list(list) when is_list(list), do: list
14041359
end

lib/elixir/test/elixir/list_test.exs

-7
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,6 @@ defmodule ListTest do
8484
assert List.last([1, 2, 3]) == 3
8585
end
8686

87-
test "zip/1" do
88-
assert List.zip([[1, 4], [2, 5], [3, 6]]) == [{1, 2, 3}, {4, 5, 6}]
89-
assert List.zip([[1, 4], [2, 5, 0], [3, 6]]) == [{1, 2, 3}, {4, 5, 6}]
90-
assert List.zip([[1], [2, 5], [3, 6]]) == [{1, 2, 3}]
91-
assert List.zip([[1, 4], [2, 5], []]) == []
92-
end
93-
9487
test "keyfind/4" do
9588
assert List.keyfind([a: 1, b: 2], :a, 0) == {:a, 1}
9689
assert List.keyfind([a: 1, b: 2], 2, 1) == {:b, 2}

0 commit comments

Comments
 (0)