compiler-plugin / arrow.meta.quotes.nameddeclaration.notstubbed / FunctionLiteral

FunctionLiteral

class FunctionLiteral : FunctionNotStubbed<KtFunctionLiteral>

”””{$(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 }

Constructors

<init> ”””{$(params)$blockExpression}””“.functionLiteralFunctionLiteral(value: KtFunctionLiteral, name: Name? = value.nameAsName, blockExpression: BlockExpression = BlockExpression(value.bodyBlockExpression))

Properties

blockExpression val blockExpression: BlockExpression
name val name: Name?
value val value: KtFunctionLiteral

Functions

identity fun ElementScope.identity(): FunctionLiteral

Extension Functions

map fun <K : KtElement> Scope<K>.map(f: (K) -> K): Scope<K>
orEmpty fun <K : KtElement> Scope<K>?.orEmpty(): Scope<K>

Do you like Arrow?

Arrow Org
<