1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix array.filter(anon_fn)

This commit is contained in:
yuyi
2020-06-10 19:18:59 +08:00
committed by GitHub
parent 12faf9fcfa
commit acf0b84523
2 changed files with 34 additions and 1 deletions

View File

@ -529,6 +529,21 @@ fn test_filter() {
//assert arr.filter(arr % 2).len == 5
}
fn test_anon_fn_filter() {
filter_num := fn (i int) bool {
return i % 2 == 0
}
assert [1,2,3,4,5].filter(filter_num) == [2,4]
}
fn test_anon_fn_arg_filter() {
a := [1,2,3,4].filter(fn (i int) bool {
return i % 2 == 0
})
assert a == [2,4]
}
fn map_test_helper_1(i int) int {
return i * i
}