From 86bfcb4a2ae24c1d33470b040ece4898783b4b4e Mon Sep 17 00:00:00 2001 From: James Lavin Date: Sun, 18 Feb 2024 15:01:51 -0500 Subject: [PATCH 1/4] document using Enum.zip to create a keyword list --- lib/elixir/lib/enum.ex | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/elixir/lib/enum.ex b/lib/elixir/lib/enum.ex index e81c961831a..c0444e774a3 100644 --- a/lib/elixir/lib/enum.ex +++ b/lib/elixir/lib/enum.ex @@ -3889,6 +3889,10 @@ defmodule Enum do Zips corresponding elements from two enumerables into a list of tuples. + Because a list of two-element tuples with atoms as the initial + tuple element is a keyword list (`Keyword`), zipping a first list + of atoms with a second list of any kind creates a keyword list. + The zipping finishes as soon as either enumerable completes. ## Examples @@ -3896,6 +3900,9 @@ defmodule Enum do iex> Enum.zip([1, 2, 3], [:a, :b, :c]) [{1, :a}, {2, :b}, {3, :c}] + iex> Enum.zip([:a, :b, :c], [1, 2, 3]) + [a: 1, b: 2, c: 3] + iex> Enum.zip([1, 2, 3, 4, 5], [:a, :b, :c]) [{1, :a}, {2, :b}, {3, :c}] From 58be7ee32529b67a9656f29ec034f622155f0f80 Mon Sep 17 00:00:00 2001 From: James Lavin Date: Sun, 18 Feb 2024 15:26:06 -0500 Subject: [PATCH 2/4] document creating keyword list from two streams using Stream.zip/2 --- lib/elixir/lib/stream.ex | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/elixir/lib/stream.ex b/lib/elixir/lib/stream.ex index 55cab5aaedf..96563098e70 100644 --- a/lib/elixir/lib/stream.ex +++ b/lib/elixir/lib/stream.ex @@ -1200,6 +1200,11 @@ defmodule Stream do @doc """ Zips two enumerables together, lazily. + Because a list of two-element tuples with atoms as the initial + tuple element is a keyword list (`Keyword`), zipping a first `Stream` + of atoms with a second `Stream` of any kind creates a `Stream` + that generates a keyword list. + The zipping finishes as soon as either enumerable completes. ## Examples @@ -1208,6 +1213,8 @@ defmodule Stream do iex> cycle = Stream.cycle([:a, :b, :c]) iex> Stream.zip(concat, cycle) |> Enum.to_list() [{1, :a}, {2, :b}, {3, :c}, {4, :a}, {5, :b}, {6, :c}] + iex> Stream.zip(cycle, concat) |> Enum.to_list() + [a: 1, b: 2, c: 3, a: 4, b: 5, c: 6] """ @spec zip(Enumerable.t(), Enumerable.t()) :: Enumerable.t() From 941e9c282d78478ff44c15a3b2ed8f55d3433cf5 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Tue, 27 Feb 2024 10:11:41 +0100 Subject: [PATCH 3/4] Update lib/elixir/lib/stream.ex --- lib/elixir/lib/stream.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/elixir/lib/stream.ex b/lib/elixir/lib/stream.ex index 96563098e70..74f3feef532 100644 --- a/lib/elixir/lib/stream.ex +++ b/lib/elixir/lib/stream.ex @@ -1200,7 +1200,7 @@ defmodule Stream do @doc """ Zips two enumerables together, lazily. - Because a list of two-element tuples with atoms as the initial + Because a list of two-element tuples with atoms as the first tuple element is a keyword list (`Keyword`), zipping a first `Stream` of atoms with a second `Stream` of any kind creates a `Stream` that generates a keyword list. From 70813a76ccbbe5d49e06040b4656d7a88f568a1d Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Tue, 27 Feb 2024 10:11:45 +0100 Subject: [PATCH 4/4] Update lib/elixir/lib/enum.ex --- lib/elixir/lib/enum.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/elixir/lib/enum.ex b/lib/elixir/lib/enum.ex index c0444e774a3..49b088aced2 100644 --- a/lib/elixir/lib/enum.ex +++ b/lib/elixir/lib/enum.ex @@ -3889,7 +3889,7 @@ defmodule Enum do Zips corresponding elements from two enumerables into a list of tuples. - Because a list of two-element tuples with atoms as the initial + Because a list of two-element tuples with atoms as the first tuple element is a keyword list (`Keyword`), zipping a first list of atoms with a second list of any kind creates a keyword list.