summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2018-12-01 16:05:53 +0100
committerEric Meadows-Jönsson <eric.meadows.jonsson@gmail.com>2018-12-01 16:05:53 +0100
commit1c502f9f4d277a3016d99f6892bf69130b417196 (patch)
treec4ec0213b131d4470d9bb69a095d4714cd088187
parent0424431e5589d8a8303180b70e736005a7729a60 (diff)
downloadelixir-1c502f9f4d277a3016d99f6892bf69130b417196.tar.gz
Improve documentation of Enum.reduce_while/3 (#8446)
-rw-r--r--lib/elixir/lib/enum.ex13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/elixir/lib/enum.ex b/lib/elixir/lib/enum.ex
index 6afac62a4..72bef7baa 100644
--- a/lib/elixir/lib/enum.ex
+++ b/lib/elixir/lib/enum.ex
@@ -1958,14 +1958,17 @@ defmodule Enum do
end
@doc """
- Reduces the `enumerable` until `fun` returns `{:halt, term}`.
+ Reduces `enumerable` until `fun` returns `{:halt, term}`.
The return value for `fun` is expected to be
* `{:cont, acc}` to continue the reduction with `acc` as the new
accumulator or
- * `{:halt, acc}` to halt the reduction and return `acc` as the return
- value of this function
+ * `{:halt, acc}` to halt the reduction
+
+ If `fun` returns `{:halt, acc}` the reduction is halted and the function
+ returns `acc`. Otherwise, if the enumerable is exhausted, the function returns
+ the accumulator of the last `{:cont, acc}`.
## Examples
@@ -1973,6 +1976,10 @@ defmodule Enum do
...> if x < 5, do: {:cont, acc + x}, else: {:halt, acc}
...> end)
10
+ iex> Enum.reduce_while(1..100, 0, fn x, acc ->
+ ...> if x > 0, do: {:cont, acc + x}, else: {:halt, acc}
+ ...> end)
+ 5050
"""
@spec reduce_while(t, any, (element, any -> {:cont, any} | {:halt, any})) :: any