From 1dd5ec99b1b8c7186378019c528a9e628e20f00a Mon Sep 17 00:00:00 2001 From: Giacomo Cavalieri Date: Tue, 18 Apr 2023 17:46:22 +0200 Subject: try_each implementation --- src/gleam/list.gleam | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') 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) { -- cgit v1.2.3