Is it possible to create extension functions that ...
# announcements
d
Is it possible to create extension functions that are only available in the context of a function's parameters?
s
uh, my first thought is no, but can you maybe share an example of how you’re thinking of using it?
d
like
something[+"name"]
where the unary plus is only available in the get function's parameter list
@Shawn
s
I guess I meant more like where the extension would be defined - what the other operand of unary + would be applied to in this context while also being used as a parameter
in any event I’m pretty certain you can’t define functions that are only exposed within the context of a function call
d
mmk
s
maybe a
get
with a different signature would be the better option
d
yeah i guess
i was trying to avoid that but i'm extending something with this get function that already has a get function that accepts a string
inline operator fun <reified T> ConfigurationSection.get(path: CharSequence): T
Is there some way to call that where it wouldn't be calling the
get(path:String): Any?
function?
s
hmm does the compiler currently complain about a platform declaration clash?
and does the other
get
also take a reified
T
?
d
No, it just goes for the original get
And no, it's a java method
Copy code
val test = config["test"]
val test: Int = config["test"]
I'm trying to get the second one to call my function
config<Int>["test"]
isn't valid though
config.get<Int>("test")
works but defeats the point of this
s
the parameterized get seems to be your only option since the Kotlin grammar doesn’t seem to have a provision for types in bracketed
get
calls
d
hmm ok
thanks for your help
👍 1