From c733b50e025577c71a3adeb215fe7345c0498cfe Mon Sep 17 00:00:00 2001 From: Giacomo Cavalieri Date: Tue, 18 Apr 2023 17:22:25 +0200 Subject: try_each definition and documentation --- src/gleam/list.gleam | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src') 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)) -- cgit v1.2.3