Any way to simplify this by getting rid of `fun St...
# codereview
Any way to simplify this by getting rid of
fun String.()
for each lamda inside this map creation?
Copy code
mapOf<String, String.() -> Unit>(
            "One" to fun String.(){ println(this) }
It gives
Type inference failed. Expected type mismatch: inferred type is Pair<String, () -> Unit> but Pair<String, String.() -> Unit> was expected
if I don't use the
fun String.()
while defining the lambda.
technically speaking you could just explicitly declare the parameter and type in the lambda:
{ str: String -> println(str)
, and that’d pass just fine as a
String.() -> Unit
, but to use
I don’t think you can avoid having to use the anonymous
at very least you could use expression body syntax:
Copy code
  "One" to fun String.() = println(this)
Thanks @Shawn. Guess I'll just have to pass in the lambda receiver type as an argument for now then.