Skip to content

Commit

Permalink
use function loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Lampese committed Mar 11, 2024
1 parent 4a4b5c1 commit 42873a5
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 42873a5

Please sign in to comment.