aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGiacomo Cavalieri <giacomo.cavalieri@icloud.com>2023-04-18 18:04:22 +0200
committerLouis Pilfold <louis@lpil.uk>2023-04-21 12:01:36 +0100
commit89f9879ff0117fd7706c8a0a4263b010f7c642f9 (patch)
tree885e3c07e2749f770910d0bc970c5120d39126b6 /src
parent1dd5ec99b1b8c7186378019c528a9e628e20f00a (diff)
downloadgleam_stdlib-89f9879ff0117fd7706c8a0a4263b010f7c642f9.tar.gz
gleam_stdlib-89f9879ff0117fd7706c8a0a4263b010f7c642f9.zip
try_each documentation examples
Diffstat (limited to 'src')
-rw-r--r--src/gleam/list.gleam27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index 09ec109..6e8b2a5 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -1571,6 +1571,33 @@ pub fn each(list: List(a), f: fn(a) -> b) -> Nil {
/// If the returned value is `Ok(new_value)`, try_each will discard the return value and call
/// the function on the next element of the list.
/// If the returned value is `Error(error)`, try_each will stop and return Nil.
+///
+/// ## Examples
+///
+/// ```gleam
+/// list.try_each(
+/// over: [1, 2, 3],
+/// with: fn(x) {
+/// io.print(int.to_string(x))
+/// Ok(Nil)
+/// },
+/// )
+/// // -> 123
+/// ```
+///
+/// ```gleam
+/// list.try_each(
+/// over: [1, 2, 3],
+/// with: fn(x) {
+/// io.print(int.to_string(x))
+/// case x {
+/// 2 -> Error(Nil)
+/// _ -> Ok(Nil)
+/// }
+/// },
+/// )
+/// // -> 12
+/// ```
pub fn try_each(over list: List(a), with fun: fn(a) -> Result(b, c)) -> Nil {
case list {
[] -> Nil