diff options
author | Giacomo Cavalieri <giacomo.cavalieri@icloud.com> | 2023-05-09 12:37:56 +0200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-05-10 18:52:46 +0100 |
commit | 431b519d9803105414417e03c0bea55deffac857 (patch) | |
tree | 9def912bd8e3456105cf8eecd150b9b290dca578 /src | |
parent | d20282d999be8db6a5cc43be540b0eeb6dda8d15 (diff) | |
download | gleam_stdlib-431b519d9803105414417e03c0bea55deffac857.tar.gz gleam_stdlib-431b519d9803105414417e03c0bea55deffac857.zip |
Do not reverse the result of `result.partition`
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/result.gleam | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/gleam/result.gleam b/src/gleam/result.gleam index 6d65459..3833add 100644 --- a/src/gleam/result.gleam +++ b/src/gleam/result.gleam @@ -368,13 +368,14 @@ pub fn all(results: List(Result(a, e))) -> Result(List(a), e) { /// Given a list of results, returns a pair where the first element is a list /// of all the values inside `Ok` and the second element is a list with all the -/// values inside `Error`. +/// values inside `Error`. The values in both lists appear in reverse order with +/// respect to their position in the original list of results. /// /// ## Examples /// /// ```gleam /// > partition([Ok(1), Error("a"), Error("b"), Ok(2)]) -/// #([1, 2], ["a", "b"]) +/// #([2, 1], ["b", "a"]) /// ``` /// pub fn partition(results: List(Result(a, e))) -> #(List(a), List(e)) { @@ -383,7 +384,7 @@ pub fn partition(results: List(Result(a, e))) -> #(List(a), List(e)) { fn do_partition(results: List(Result(a, e)), oks: List(a), errors: List(e)) { case results { - [] -> #(list.reverse(oks), list.reverse(errors)) + [] -> #(oks, errors) [Ok(a), ..rest] -> do_partition(rest, [a, ..oks], errors) [Error(e), ..rest] -> do_partition(rest, oks, [e, ..errors]) } |