From 84e345b04ef5d907f0418a06d1536f8ec2cc31e0 Mon Sep 17 00:00:00 2001 From: sergeych Date: Tue, 12 Aug 2025 05:01:02 +0300 Subject: [PATCH] more docs on function annotations --- docs/advanced_topics.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/advanced_topics.md b/docs/advanced_topics.md index 47b8978..36a3cb6 100644 --- a/docs/advanced_topics.md +++ b/docs/advanced_topics.md @@ -136,6 +136,25 @@ When used without params, annotation calls a function with two arguments: actual assertEquals(111, foo( 10 )) >>> void -Function annotation can have more args specified at call time. +Function annotation can have more args specified at call time. There arguments must follow two mandatory ones (name and body). Use default values in order to allow parameterless annotation to be used simultaneously. + + val registered = Map() + + // it is recommended to provide defaults for extra parameters: + fun Registered(name, body, overrideName = null) { + registered[ overrideName ?: name ] = body + body + } + + // witout parameters is Ok as we provided default value + @Registered + fun foo() { "called foo" } + + @Registered("bar") + fun foo2() { "called foo2" } + + assertEquals(registered["foo"](), "called foo") + assertEquals(registered["bar"](), "called foo2") + >>> void [parallelism]: parallelism.md