Does Kotlin have UFCS? <https://en.m.wikipedia.org...
# language-proposals
a
Does Kotlin have UFCS? https://en.m.wikipedia.org/wiki/Uniform_Function_Call_Syntax I didn't find any related documentation. What would it take to support UFCS?
h
As far as I understand UFCS: It is called receiver in Kotlin: https://kotlinlang.org/docs/lambdas.html#function-literals-with-receiver You can also create you own extension functions.
👍 1
m
I think the idea of UFCS is that you don't need the extension function / receiver concept anymore. The first parameter just becomes specially privileged in the syntax, by convention.
h
you can call
fun A.foo(b: B): C
with
foo(a, b)
the compiler converts
a.foo(b)
anyway 🙂
x
UFCS sounds like this is the
friend
syntax from c++
e
UFCS comes from a different philosophy. A philosophy in Kotlin is that the function's author determines how the function is supposed to used. You, as a function author, decide if you want your function to be used like
foo(a, b)
, or as a
a.foo(b)
. While the philosophy of UFCS is that this decision should be made by the caller.
h
But if you use a lambda, both calling options are possible. Why is this case different?
Copy code
val foo = fun Int.(s: String) { }

foo(42, "")
42.foo("")
e
That was done to simplify lambda types hierarchy, so that they are all interchangeable.