diff options
author | Giacomo Cavalieri <giacomo.cavalieri@icloud.com> | 2023-04-18 17:22:25 +0200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-04-21 12:01:36 +0100 |
commit | c733b50e025577c71a3adeb215fe7345c0498cfe (patch) | |
tree | efe15810e9dde0da79d5300f3857514ef3efcd5b /src | |
parent | 2651aa701a564e72705897a3c54a4264ff51c517 (diff) | |
download | gleam_stdlib-c733b50e025577c71a3adeb215fe7345c0498cfe.tar.gz gleam_stdlib-c733b50e025577c71a3adeb215fe7345c0498cfe.zip |
try_each definition and documentation
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/list.gleam | 10 |
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)) |