Skip to content

Commit

Permalink
use function loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Lampese authored and Yoorkin committed Mar 12, 2024
1 parent 1531b21 commit 031a0d6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions array/array.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,14 @@ test "from_array" {
}

pub fn fold[T, U](self : Array[T], f : (T, U) -> U, init : U) -> U {
for i = 0, acc = init ; i < self.length() ; {
continue i + 1, f(self[i], acc)
} else {
acc
loop 0, init {
i, acc =>
if i < self.length() {
continue i + 1,
f(self[i], acc)
} else {
acc
}
}
}

Expand Down

0 comments on commit 031a0d6

Please sign in to comment.