From aef756a3fde8ff507741c5039a0357c2aae476e4 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 22 Apr 2020 07:23:05 +0200 Subject: [PATCH] docs: high order functions --- doc/docs.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/doc/docs.md b/doc/docs.md index 011429795d..21dac48ad0 100644 --- a/doc/docs.md +++ b/doc/docs.md @@ -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 + }) } ```