Hi, wondering if I can have anonymous/named extens...
# announcements
j
Hi, wondering if I can have anonymous/named extension function like following
Copy code
val x = fun Int.() { this.toString() }
1.x()
can be 'x' defined as anonymous/named extension property ? so I could have
Copy code
1.x
?
👀 1
m
You would define it on Any if you want it available on everything. But remember that this will add to the namespace/help for everything.
Copy code
fun Any.x() { this.toString() }
j
well, isn't it same as my 1st example ? basically i'm looking for
Copy code
fun test() {
  val x = fun Int.() { this.toString() }
  1.x()
  val y = //?
  1.y
}
in class I'd have easily something like
Copy code
class Test {
    val Int.y get() = toString()

    fun test() {            
        val x = fun Int.() { this.toString() }
        1.x()
        1.y 
    }
}
But looking if there is away to define it in the scope of the 'test' function
s
local extension properties are explicitly disallowed
👍 1
j
@Shawn ah ta, kinda glad that they are 😄