For comparison, there is extension in kotlin:
see: https://kotlinlang.org/docs/reference/extensions.html
With this functionality we can make sql dsl:
fun search(name: String, minAge: Int?) = list {
where {
upper(c.name) like upper("%$name%")
if (minAge != null) {
and {
c.age gte minAge
}
}
}
}
In this example “where” is declared as:
fun where(op: WhereExpr.() -> Unit) =
add(WhereExpr(this), op)
see:https://github.com/edvin/kdbc/blob/master/src/main/kotlin/kdbc/expression.kt
This is equivalent of scope injection.
It’s very convenient.