Matias Reparaz
06/25/2021, 12:53 PMdmitriy.novozhilov
06/25/2021, 1:23 PMfoo(a, b, c) { bar() }
foo(a, b, c, { bar() })
So when you call f("hello, world") { it.toUpperCase() }
in your example is is desugared to f.invoke("hello, world", { it.toUpperCase() })
, which is incorrect, because it should be f.invoke("").invoke({ it.toUpperCase() })
Matias Reparaz
06/25/2021, 2:44 PMf("hello, world").invoke {it.uppercase()}.also { println("f: $it") }
dmitriy.novozhilov
06/25/2021, 5:17 PMf("hello, world")() { it.uppercase() }
// same as
val x = f("hello, world")
x() { it.uppercase() }
Matias Reparaz
06/25/2021, 5:24 PMval a
has type ((String) -> String) -> String
ephemient
06/25/2021, 5:56 PMf() == f.invoke()
(if f
is a val, var, object)
f() {...} == f({...}) == f {...}
empty parens before lambda can be present or omittedf1 { it.uppercase() }
f1() { it.uppercase() }
f1({ it.uppercase() })
f1.invoke { it.uppercase() }
f1.invoke() { it.uppercase() }
f1.invoke({ it.uppercase() })
are all equivalentMatias Reparaz
06/25/2021, 6:05 PM