Skip to content

Commit

Permalink
refacror: use for instead of loop
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeZhangBorui authored and bobzhang committed Mar 14, 2024
1 parent 81b45dc commit 99c750f
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions array/array.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,11 @@ test "from_array" {
}

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

Expand Down

0 comments on commit 99c750f

Please sign in to comment.