aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChuck Daniels <cjdaniels4@gmail.com>2023-03-23 12:59:31 -0400
committerLouis Pilfold <louis@lpil.uk>2023-03-23 19:48:27 +0000
commitb2b07ef0612cc549508b757826d8d143d9587119 (patch)
treec45ae71d2cc53f50afb65360f7d357db65c1d2f1 /src
parent35b5049025d6b09fa5979840b340ba63d5c948d9 (diff)
downloadgleam_stdlib-b2b07ef0612cc549508b757826d8d143d9587119.tar.gz
gleam_stdlib-b2b07ef0612cc549508b757826d8d143d9587119.zip
Make iterator.any/all TCO eligible in JavaScript
Fixes #427
Diffstat (limited to 'src')
-rw-r--r--src/gleam/iterator.gleam16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam
index 89d50a8..1486ae3 100644
--- a/src/gleam/iterator.gleam
+++ b/src/gleam/iterator.gleam
@@ -995,7 +995,11 @@ fn do_any(
) -> Bool {
case continuation() {
Stop -> False
- Continue(e, next) -> predicate(e) || do_any(next, predicate)
+ Continue(e, next) ->
+ case predicate(e) {
+ True -> True
+ False -> do_any(next, predicate)
+ }
}
}
@@ -1037,7 +1041,11 @@ fn do_all(
) -> Bool {
case continuation() {
Stop -> True
- Continue(e, next) -> predicate(e) && do_all(next, predicate)
+ Continue(e, next) ->
+ case predicate(e) {
+ True -> do_all(next, predicate)
+ False -> False
+ }
}
}
@@ -1391,10 +1399,10 @@ fn do_length(over continuation: fn() -> Action(e), with length: Int) -> Int {
/// Counts the number of elements in the given iterator.
///
/// This function has to traverse the entire iterator to count its elements,
-/// so it runs in linear time.
+/// so it runs in linear time.
///
/// ## Examples
-///
+///
/// ```gleam
/// > empty() |> length
/// 0