Комментарии:
I use them to clean the code in large functions. If anything goes wrong, the stack trace tells me the name of the inner function.
Ответитьtoo lazy to cut the last bit of this video off? lol same
ОтветитьIt’s good for a cleaner code but you didn’t mention whether nested function able to access outer function’s local variables
ОтветитьIt's also quite useful to do recursive actions without modifying the outer function's parameters.
I also like to use it when I need to do a "helper" method that does the bulk of the work, we can avoid passing arguments from the outerscope.
what about lamda functions i use it in this scenario instead of that normal fuction
is there is a diff ?
It's a pretty common pattern in compose
ОтветитьI like to use nested functions for helper functions that break up proceases without having to use comments.
ОтветитьShould have cut out the last second 😅
ОтветитьWhy not just make a private function in the same file?
ОтветитьI just use lamda variable in this case
ОтветитьIts quite useful when dealing with recursive functions as you can have one function which accepts the start parameters and have an inner function for the actual recursive call with an accumulator initialized. Also works great when writing tailrec functions
ОтветитьI use a lot, even if not repetitive code, like if a function does multiple tasks, and each task is a big chunck of code, then I move each chunck into an inner function, makes the code readable for me
ОтветитьUseful in Composable functions, when you do not want to pass many parameters to nested function
ОтветитьYou could also put it in a lamda.
I.e:
val addNumbers: (Int, Int) -> Int = { x, y -> x + y }
val result = addNumbers(2, 3) // result = 5
Looks cleaner imo
what is better, lambas inside a function or nested functions?
ОтветитьI still do not see the use of it being a nested function. Need to understand it better.
ОтветитьKotlin is the best language.
ОтветитьHmmm
Ответитьoh nice cool. ishlarizga omad . hamma video va contentlaringiz ajoyib va foydali.
ОтветитьReally useful feature for me.
ОтветитьNice trick, I once had a scenario where this could be useful and was thinking if it's possible 😂
ОтветитьInteresting but still it looks wrong to me 😅, may be we need to get used to it
Ответитьthat's mindblowing!
Ответить