arrays: fix arrays.fold, when the init value in the call, is an array (#21921)

This commit is contained in:
Felipe Pena 2024-07-24 10:37:20 -03:00 committed by GitHub
parent b5ba466488
commit d186c3946f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View file

@ -331,7 +331,12 @@ pub fn filter_indexed[T](array []T, predicate fn (idx int, elem T) bool) []T {
// assert r == 5
// ```
pub fn fold[T, R](array []T, init R, fold_op fn (acc R, elem T) R) R {
mut value := init
mut value := R{}
$if R is $array {
value = init.clone()
} $else {
value = init
}
for e in array {
value = fold_op(value, e)