<@U5V3J5YCX> Define the function in the dsl class?
# announcements
k
@Michael Define the function in the dsl class?
m
This is all new to me. 😄 Trying to figure out how to structure the definitions: I tried
Copy code
fun filterOn(init: MyClass.() -> Unit): MyClass {
    infix fun String.equals(value: Any) = Condition(this, value, Operator.EQ)
    infix fun String.contains(value: Any) = Condition(this, value, Operator.CONTAINS)
    infix fun String.isNotNull(value: Any) = Condition(this, value, Operator.ISNOTNULL)

    MyClass().apply(init)

}
, but the infix functions aren’t available within the
init
function
m
Thanks! Reading now…
m
You can do something like this:
Copy code
object DSL {
    infix fun <http://String.space|String.space>(that: String): String = "$this $that"
}

fun dsl(f: DSL.() -> Unit) = DSL.f()

fun main(args: Array<String>) {
    dsl {
        "Hello" space "world!"
    }
}
m
I’m getting there now. 🙂 Thanks! I can’t say I 100% understand yet - but it’s starting to click.