compiler-plugin / arrow.meta.quotes.nameddeclaration.notstubbed / FunctionLiteral / <init>

<init>

FunctionLiteral(value: KtFunctionLiteral, name: Name? = value.nameAsName, blockExpression: BlockExpression = BlockExpression(value.bodyBlockExpression))

”””{$(params)$blockExpression}””“.functionLiteral

A template destructuring Scope for a KtFunctionLiteral.

import arrow.meta.Meta
import arrow.meta.CliPlugin
import arrow.meta.invoke
import arrow.meta.quotes.Transform
import arrow.meta.quotes.functionLiteral

val Meta.reformatFunctionLiteral: CliPlugin
   get() =
     "Reformat Function Literal" {
       meta(
         functionLiteral({ true }) { functionNotStubbed ->
           Transform.replace(
             replacing = functionNotStubbed,
             newDeclaration = """{$`(params)`$blockExpression}""".functionLiteral
           )
         }
       )
     }

A function literal is a special notation to simplify how a function is defined. There are two types of function literals in Kotlin:

Lambda expression

A lambda expression is a short way to define a function. It tends to be more explicit than anonymous functions:

val increment: (Int) -> Unit = { x -> x + 1 }

Anonymous function

An anonymous function is just another way to define a function:

val increment: (Int) -> Unit = fun(x) { x + 1 }

Do you like Arrow?

Arrow Org
<