aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiacomo Cavalieri <giacomo.cavalieri@icloud.com>2023-05-07 09:54:58 +0200
committerLouis Pilfold <louis@lpil.uk>2023-05-10 18:52:46 +0100
commit227c5954a77a7d42446ed100dd8b10cf4055408a (patch)
tree9c5cb512bc367bbda51645c1d7d5b6a6607ba3ee
parent68faee833ac8a4b6c41a58d00080866e5a8fcaf3 (diff)
downloadgleam_stdlib-227c5954a77a7d42446ed100dd8b10cf4055408a.tar.gz
gleam_stdlib-227c5954a77a7d42446ed100dd8b10cf4055408a.zip
`result.partition` documentation
-rw-r--r--src/gleam/result.gleam17
1 files changed, 16 insertions, 1 deletions
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([])