mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +03:00
checker: allow for each(a, |x| println(x))
, i.e. using lambda expressions, when expecting fn (x int)
This commit is contained in:
parent
b81a5325ef
commit
e115d4461c
2 changed files with 55 additions and 6 deletions
|
@ -33,3 +33,17 @@ fn test_all() {
|
|||
assert !a.all(|x| x > 4)
|
||||
assert a.all(|x| x < 40)
|
||||
}
|
||||
|
||||
fn each(a []int, cb fn (x int)) {
|
||||
for x in a {
|
||||
cb(x)
|
||||
}
|
||||
}
|
||||
|
||||
fn test_using_lambda_expr_that_does_not_return_as_cb() {
|
||||
each(a, fn (x int) {
|
||||
println(x)
|
||||
})
|
||||
each(a, |x| println(x))
|
||||
each(a, |x| dump(x))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue