From 227c5954a77a7d42446ed100dd8b10cf4055408a Mon Sep 17 00:00:00 2001 From: Giacomo Cavalieri Date: Sun, 7 May 2023 09:54:58 +0200 Subject: `result.partition` documentation --- src/gleam/result.gleam | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gleam/result.gleam b/src/gleam/result.gleam index 100d36d..4f3ecd9 100644 --- a/src/gleam/result.gleam +++ b/src/gleam/result.gleam @@ -366,7 +366,22 @@ pub fn all(results: List(Result(a, e))) -> Result(List(a), e) { list.try_map(results, fn(x) { x }) } -/// TODO Add doc! +/// Combines a list of results into a single result. +/// If all elements in the list are `Ok` then returns an `Ok` holding the list of values. +/// If any element is `Error` then returns an `Error` holding the list of all errors. +/// +/// ## Examples +/// +/// ```gleam +/// > partition([Ok(1), Ok(2)]) +/// Ok([1, 2]) +/// ``` +/// +/// ```gleam +/// > partition([Ok(1), Error("a"), Error("b")]) +/// Error(["a", "b"]) +/// ``` +/// pub fn partition(results: List(Result(a, e))) -> Result(List(a), List(e)) { case results { [] -> Ok([]) -- cgit v1.2.3