aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Attard <robert.attard@mail.mcgill.ca>2021-07-13 10:23:14 -0400
committerLouis Pilfold <louis@lpil.uk>2021-07-13 17:11:38 +0100
commitd268cee7c72f146ef0b8f5118c9fe3c1b1880c8f (patch)
tree281023a32d0febb544a669c59c8a81df42375046 /src
parent178d5a18ec040472ca695e78e9149aef0a0e3137 (diff)
downloadgleam_stdlib-d268cee7c72f146ef0b8f5118c9fe3c1b1880c8f.tar.gz
gleam_stdlib-d268cee7c72f146ef0b8f5118c9fe3c1b1880c8f.zip
move into if erlang block
Diffstat (limited to 'src')
-rw-r--r--src/gleam/iterator.gleam84
1 files changed, 42 insertions, 42 deletions
diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam
index 414956d..fc296e9 100644
--- a/src/gleam/iterator.gleam
+++ b/src/gleam/iterator.gleam
@@ -1035,49 +1035,49 @@ if erlang {
fn() { do_interleave(left.continuation, right.continuation) }
|> Iterator
}
-}
-fn do_fold_until(
- continuation: fn() -> Action(e),
- f: fn(e, acc) -> list.ContinueOrStop(acc),
- accumulator: acc,
-) -> acc {
- case continuation() {
- Stop -> accumulator
- Continue(elem, next) ->
- case f(elem, accumulator) {
- list.Continue(accumulator) -> do_fold_until(next, f, accumulator)
- list.Stop(accumulator) -> accumulator
- }
+ fn do_fold_until(
+ continuation: fn() -> Action(e),
+ f: fn(e, acc) -> list.ContinueOrStop(acc),
+ accumulator: acc,
+ ) -> acc {
+ case continuation() {
+ Stop -> accumulator
+ Continue(elem, next) ->
+ case f(elem, accumulator) {
+ list.Continue(accumulator) -> do_fold_until(next, f, accumulator)
+ list.Stop(accumulator) -> accumulator
+ }
+ }
}
-}
-/// Like `fold`, `fold_until` reduces an iterator of elements into a single value by calling a given
-/// function on each element in turn, but uses a `list.ContinueOrStop` to determine
-/// whether or not to keep iterating.
-///
-/// If called on an iterator of infinite length then this function will only ever
-/// return if the give function returns list.Stop.
-///
-///
-/// ## Examples
-/// > let f = fn(e, acc) {
-/// > case e {
-/// > _ if e < 4 -> list.Continue(e + acc)
-/// > _ -> list.Stop(acc)
-/// > }
-/// > }
-/// >
-/// > [1, 2, 3, 4]
-/// > |> from_list
-/// > |> iterator.fold_until(from: acc, with: f)
-/// 6
-///
-pub fn fold_until(
- over iterator: Iterator(e),
- from initial: acc,
- with f: fn(e, acc) -> list.ContinueOrStop(acc),
-) -> acc {
- iterator.continuation
- |> do_fold_until(f, initial)
+ /// Like `fold`, `fold_until` reduces an iterator of elements into a single value by calling a given
+ /// function on each element in turn, but uses a `list.ContinueOrStop` to determine
+ /// whether or not to keep iterating.
+ ///
+ /// If called on an iterator of infinite length then this function will only ever
+ /// return if the give function returns list.Stop.
+ ///
+ ///
+ /// ## Examples
+ /// > let f = fn(e, acc) {
+ /// > case e {
+ /// > _ if e < 4 -> list.Continue(e + acc)
+ /// > _ -> list.Stop(acc)
+ /// > }
+ /// > }
+ /// >
+ /// > [1, 2, 3, 4]
+ /// > |> from_list
+ /// > |> iterator.fold_until(from: acc, with: f)
+ /// 6
+ ///
+ pub fn fold_until(
+ over iterator: Iterator(e),
+ from initial: acc,
+ with f: fn(e, acc) -> list.ContinueOrStop(acc),
+ ) -> acc {
+ iterator.continuation
+ |> do_fold_until(f, initial)
+ }
}