javapoet-dsl / com.mostlycertain.javapoetdsl / lambda

lambda

fun lambda(vararg parameterNames: String, block: CodeFunc): CodeExpression
fun lambda(parameterNames: List<String>, block: CodeFunc): CodeExpression

Render a lambda function.

The lambda is always rendered with parens around the parameters. The result looks like this:

(<parameterNames>) -> {
    <block>
}

NOTE: A line break is NOT rendered after the closing curly brace.

Parameters

parameterNames - Ordered list of parameter names for the lambda.

block - Function to render the body of the lambda.

fun lambda(parameterNames: List<String>, expression: CodeExpression): CodeExpression
fun lambda(vararg parameterNames: String, expression: CodeExpression): CodeExpression

Render a lambda function with a single expression and no curly braces.

The lambda is always rendered with parens around the parameters. The result looks like this:

(<parameterNames>) -> <expression>

NOTE: A line break is NOT rendered after the expression.

Parameters

parameterNames - Ordered list of parameter names for the lambda.

expression - Expression that produces the lambda result.

fun lambda(expression: CodeExpression): CodeExpression

Render a lambda function with a single expression and no curly braces or parameters.

The result looks like this:

() -> <expression>

NOTE: A line break is NOT rendered after the expression.

Parameters

expression - Expression that produces the lambda result.