aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGareth Pendleton <gareth.sidebottom@gmail.com>2024-09-05 11:50:48 +0100
committerGitHub <noreply@github.com>2024-09-05 11:50:48 +0100
commit363de5ebd94d6c975d4f232955050d364512d230 (patch)
tree593b748e8b4f4b8b6d6d8cae7d2d4f7231de3016 /src
parentee334747949c6696a0128d1ce709078ecc564598 (diff)
downloadgleam_stdlib-363de5ebd94d6c975d4f232955050d364512d230.tar.gz
gleam_stdlib-363de5ebd94d6c975d4f232955050d364512d230.zip
make iterator.do_try_fold tail-recursive (#689)
Co-authored-by: Gareth Pendleton <gareth.pendleton@ninthwave.co.uk>
Diffstat (limited to 'src')
-rw-r--r--src/gleam/iterator.gleam6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam
index ee38bdc..336c0a1 100644
--- a/src/gleam/iterator.gleam
+++ b/src/gleam/iterator.gleam
@@ -1467,8 +1467,10 @@ fn do_try_fold(
case continuation() {
Stop -> Ok(accumulator)
Continue(elem, next) -> {
- use accumulator <- result.try(f(accumulator, elem))
- do_try_fold(next, f, accumulator)
+ case f(accumulator, elem) {
+ Ok(result) -> do_try_fold(next, f, result)
+ Error(_) as error -> error
+ }
}
}
}