diff options
author | Giacomo Cavalieri <giacomo.cavalieri@icloud.com> | 2023-04-18 17:46:22 +0200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-04-21 12:01:36 +0100 |
commit | 1dd5ec99b1b8c7186378019c528a9e628e20f00a (patch) | |
tree | 34bb4c5b72211ae2142a71cbb15276166f2c421b /src | |
parent | 8afbd47799925c962521e72b42664ceafd413a55 (diff) | |
download | gleam_stdlib-1dd5ec99b1b8c7186378019c528a9e628e20f00a.tar.gz gleam_stdlib-1dd5ec99b1b8c7186378019c528a9e628e20f00a.zip |
try_each implementation
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/list.gleam | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam index dcea121..09ec109 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -1572,7 +1572,14 @@ pub fn each(list: List(a), f: fn(a) -> b) -> Nil { /// 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 + case list { + [] -> Nil + [x, ..xs] -> + case fun(x) { + Ok(_) -> try_each(over: xs, with: fun) + Error(_) -> Nil + } + } } fn do_partition(list, categorise, trues, falses) { |