Using operators with lambdas

suggest change

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%") }

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents