Kotlin DSL Building Using operators with lambdas


Example

If you have:

val r = Random(233)
infix inline operator fun Int.rem(block: () -> Unit) {
  if (r.nextInt(100) < this) block()
}

You can write the following DSL-like code:

20 % { println("The possibility you see this message is 20%") }