Nested functions/ nested functions as data: Top or...
# functional
c
Nested functions/ nested functions as data: Top or flop?
y
I'd say if you're in that situation,
fun interfaces
make a lot more sense, and will surely look nicer as a type
k
By "nested functions" do you mean (a) functions defined in the body of another function, or (b) function-typed parameters? If you mean (a), then how are fun interfaces (suggested by Youssef) of use in this situation?
y
I assumed he meant the second because he specified "as data", but maybe I misinterpreted. Nested functions are okay. Sometimes they can result in a bit of performance overhead, but most of the time they're okay
c
React uses nested functions excessive. Therefore I asked myself, if they are useful in some way in backend. I think most of the time they make code much less readable and debugable. But I also had the case in codewars, where they where pretty useful:
Copy code
val f : (Int, Int, Int) -> Int = { x: Int, mult: Int, inc: Int -> mult*x+inc }
y
I would suggest writing these as top-level functions, or at least with the
fun
syntax while nested:
Copy code
fun f(x: Int, mult:Int, inc:Int) = mult * x + inc
🙌 1