compiler-plugin / arrow.meta.quotes.expression.loopexpression / ForExpression
class ForExpression :
LoopExpression
<KtForExpression>
”"”for ($(param)
in $loopRange) $body”””.for
A template destructuring Scope for a KtForExpression.
import arrow.meta.Meta
import arrow.meta.CliPlugin
import arrow.meta.invoke
import arrow.meta.quotes.Transform
import arrow.meta.quotes.forExpression
val Meta.reformatFor: CliPlugin
get() =
"Reformat For Expression" {
meta(
forExpression(this, { true }) { loopExpression ->
Transform.replace(
replacing = loopExpression,
newDeclaration = if (destructuringDeclaration.entries.isEmpty()) {
"""for ($`(param)` in $loopRange) $body""".`for`
} else {
"""for ((${destructuringDeclaration.entries}) in $loopRange) $body""".`for`
}
)
}
)
}
<init> | ”"”for ($(param) in $loopRange) $body”””.for ForExpression(value: KtForExpression, (param): Parameter = Parameter(value.loopParameter), loopRange: Scope <KtExpression> = Scope(value.loopRange), destructuringDeclaration: DestructuringDeclaration = DestructuringDeclaration(value.destructuringDeclaration)) |
(param) | val (param): Parameter |
destructuringDeclaration | val destructuringDeclaration: DestructuringDeclaration |
loopRange | val loopRange: Scope <KtExpression> |
value | val value: KtForExpression |
identity | fun ElementScope .identity(): ForExpression |
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?
✖