Closed aalekhpatel07 closed 2 years ago
seem like a problem with closures used in that context. assigning the anon fn to a variable first, than passing that to filter seems to workaround the problem for some reason
fn battle(t Tournament, idx int) Tournament {
if t.words.len == 1 {
return t
}
f1 := fn [idx] (w string) bool {
return w[idx] == 48
}
zeroes := t.words.filter(f1)
f2 := fn [idx] (w string) bool {
return w[idx] == 49
}
ones := t.words.filter(f2)
if ones.len >= zeroes.len {
return Tournament{ones}
}
return Tournament{zeroes}
}
It might be a valid workaround but I think I'd be interested to learn a reason for why binding closures to variables before passing them is okay but passing raw closures are not.
Fixed.
V doctor:
What did you do?
v -g -o vdbg cmd/v && vdbg ./src/03.v
What did you expect to see?
Anything but a mysterious "too few arguments to function builder error".
What did you see instead?