Using extensions with lambdas

suggest change

If you have:

operator fun <R> String.invoke(block: () -> R) = {
  try { block.invoke() }
  catch (e: AssertException) { System.err.println("$this\n${e.message}") }
}

You can write the following DSL-like code:

"it should return 2" {
   parse("1 + 1").buildAST().evaluate() shouldBe 2
}

If you feel confused with shouldBe above, see the example Infix approach to build DSL.

Feedback about page:

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



Table Of Contents