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

docs: high order functions

This commit is contained in:
Alexander Medvednikov 2020-04-22 07:23:05 +02:00 committed by GitHub
parent 50436a0e4a
commit aef756a3fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -689,7 +689,7 @@ fn register(u User) User {
user = register(user)
```
## High order functions
## Anonymous & high order functions
```v
fn sqr(n int) int {
@ -702,6 +702,17 @@ fn run(value int, op fn(int) int) int {
fn main() {
println(run(5, sqr)) // "25"
// Anonymous functions can be declared inside other functions:
double_fn := fn(n int) int {
return n + n
}
println(run(5, double_fn)) // "10"
// Functions can be passed around without assigning them to variables:
res := run(5, fn(n int) int {
return n + n
})
}
```