Call extension function without brackets like DSL

Hi Devs,

I’ve created a extension function for visibility of a view as follows,

fun View.gone( ) {
this.visibility = View.GONE
}

Then I call this extension function to gone the view as

val btn : Button

btn.gone()

Using DSL style I need a function call like infix function without brackets

Examples
btn.gone
btn.visible
btn.invisible

I hope you guys working on this.
Thank you

Basically, this syntax looks like accessing a property, right? so what you’re gonna do is simply:

val view.gone: Unit get() { this.visibility = View.GONE }

A getter with a side-effect is likely to be highly misleading!

Getters are expected to behave like reading a property: they shouldn’t have any visible side-effects (in particular, they shouldn’t change the object’s visible state), or take significant amounts of time (e.g. accessing external resources such as DBs), or return different results (unless the object changes its visible state), or throw exceptions.

I know that some conventions are loosened for DSLs, but this looks dangerous…

3 Likes