From: Brendan Hansen Date: Wed, 6 Dec 2023 16:29:30 +0000 (-0600) Subject: fixed: critical bug in `iter.fold` producing wrong values X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=743e6a296d05d45ecb3e70873764235e0c36cbbc;p=onyx.git fixed: critical bug in `iter.fold` producing wrong values --- diff --git a/core/container/iter.onyx b/core/container/iter.onyx index ca4f8252..e37de430 100644 --- a/core/container/iter.onyx +++ b/core/container/iter.onyx @@ -749,11 +749,13 @@ fold :: macro (it: $T/Iterable, init: $R, combine: $S) => #overload fold :: (it: Iterator($T), initial_value: $R, combine: (T, R) -> R) -> R { + result := initial_value; + for value: it { - initial_value = combine(value, initial_value); + result = combine(value, result); } - return initial_value; + return result; }