Skip to content

82 Result builders ​

@BuildWith(Words.class) transforms expression statements in the callback into ordered add calls. finish() returns the accumulated String; each callback execution gets a fresh builder.

norm
import std.build.BuildWith
import std.build.ResultBuilder

class Words implements ResultBuilder<String, String> {
  private String text = ""
  Void add(String value) { text = text + value }
  String finish() { text }
}

String words(@BuildWith(Words.class) Function<String()> content) { content() }

main() {
  printLine(words { "Learn" " " "Norm" })
}

Expected output:

text
Learn Norm

Try it: Add another string expression to the block.

Precise rules: Reference.

Norm 0.25