aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGiacomo Cavalieri <giacomo.cavalieri@icloud.com>2023-04-18 17:22:25 +0200
committerLouis Pilfold <louis@lpil.uk>2023-04-21 12:01:36 +0100
commitc733b50e025577c71a3adeb215fe7345c0498cfe (patch)
treeefe15810e9dde0da79d5300f3857514ef3efcd5b /src
parent2651aa701a564e72705897a3c54a4264ff51c517 (diff)
downloadgleam_stdlib-c733b50e025577c71a3adeb215fe7345c0498cfe.tar.gz
gleam_stdlib-c733b50e025577c71a3adeb215fe7345c0498cfe.zip
try_each definition and documentation
Diffstat (limited to 'src')
-rw-r--r--src/gleam/list.gleam10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam
index 5f116c3..dcea121 100644
--- a/src/gleam/list.gleam
+++ b/src/gleam/list.gleam
@@ -1565,6 +1565,16 @@ pub fn each(list: List(a), f: fn(a) -> b) -> Nil {
}
}
+/// A variant of each that might fail.
+///
+/// Takes a function that returns a result and tries to calls it for each element in a list.
+/// 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.
+pub fn try_each(over list: List(a), with fun: fn(a) -> Result(b, c)) -> Nil {
+ todo
+}
+
fn do_partition(list, categorise, trues, falses) {
case list {
[] -> #(reverse(trues), reverse(falses))