Any chance to have something similar to an eta red...
# functional
g
Any chance to have something similar to an eta reduce in Kotlin?
e
What is the problem you are trying to solve?
g
It’s just styling, I would like to say that a function is equal to another function, without manually passing the parameter
e
why would you need this?
g
to delegate, for example
Maybe I’ve been spoiled by haskell
e
can you give a snippet of code?
(can be in Haskell)
g
Copy code
funName i = otherFun i
vs
funName = otherFun

fun funName(i: A) = otherFun(i)
in kotlin I can do that provided that it’s not a function, but a
val
e.g.
Copy code
val a:(Int)->String = ::otherFun
e
Yes. What’s the problem with that?
And you can even omit type.
g
that I need the original declaration to be a
val
and not a
fun
, right? 🤔
e
But why it matter? Like there’s no difference between them in Haskell.
g
I don’t always control the function
maybe it comes from an interface
and I want to “delegate” the implementation
I guess in Kotlin would be something like: fun funName by otherFun
e
There are some plans for
fun a(i: Int) by ::otherFun
but not in the near future.
🤩 1
💯 1
✔️ 1
🙏 1
g
Well, nice to hear that 😄
e
For now, if you come from Haskell you can use
val
everywhere, even in your interfaces.
g
Yes, I’m doing that when I control them Thank you!