docs: high order functions

pull/4550/head
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
1 changed files with 12 additions and 1 deletions

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
})
}
```