Hi, i've got a good one for you :smiley: Can't fi...
# announcements
s
Hi, i've got a good one for you 😃 Can't find the right way to set the Type Parameter for an infix any ideas ?
Copy code
class SomeHolder {

    private val someMap = mutableMapOf<String,Any()>


    private infix fun T String.from(transformation : (Any?)-> T?) =
        transformation.invoke(someMap[this])

    fun SomeHolder.test() {
        
          //works but no return type assurance
          "test" from {input ->
            when(input) {
                is String -> input.toFloatOrNull()
                else -> null
            }
        }

        //not working
        "otherTest" from<Float> { input : Any? ->
            when(input) {
                is String -> input.toFloatOrNull()
                else -> null
            }
        }
        
        //not working
        <Float> "yet another" from { input : Any? ->
            when(input) {
                is String -> input.toFloatOrNull()
                else -> null
            }
        }     
        
        //not working
        "yet another" <Float>from { input : Any? ->
            when(input) {
                is String -> input.toFloatOrNull()
                else -> null
            }
        }
        
        //not working
        "arrrg" from { input : Any? ->
            when(input) {
                is String -> input.toFloatOrNull()
                else -> null
            }
        }<Float>
    }

}
a
What do you mean with
no return type assurance
?
s
by setting the type parameter at the method (see all not working statements) it want to enforce the return type of the transformation to be a specific type
<Float>
but i haven't found a way to set a TypeParameter in an inline function
i can define one
but can't use it
a
i don't think its possible define the Type parameter of an infix function right now
but you can still use it like a normal function which is only a single dot added
s
yeah i know
i just wanted to point out and see if a) im doing it wrong or b) it is just not yet possible
if b) i would like to propose the my first variant from<Float>
😃
did i say if ? i meant to say when
a
and then you end up with
a +<MySuperCoolClass> b
s
well not on operator fun that would look crazy
a
an operator is just a regular infix function too (with the added property of being an operator)