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
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
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.
I imagine it'd be useful when you have some value in the scope of the parent function that you either don't want to calculate again in a regular class-level function or you simply can't because no other class-level functions would have access to that data. I've personally run into situations where this might've been useful but I tend to just use lambdas instead.
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
Probably the only use case I can get behind
Useful in Composable functions, when you do not want to pass many parameters to nested function
Probably not a good idea
I like to use nested functions for helper functions that break up proceases without having to use comments.
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
It's a pretty common pattern in compose
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.
that's mindblowing!
Itâs good for a cleaner code but you didnât mention whether nested function able to access outer functionâs local variables
Interesting but still it looks wrong to me đ , may be we need to get used to it
what is better, lambas inside a function or nested functions?
Nice trick, I once had a scenario where this could be useful and was thinking if it's possible đ
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
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.
oh nice cool. ishlarizga omad . hamma video va contentlaringiz ajoyib va foydali.
hi guys, in this case, why not use a lambda func?
what about lamda functions i use it in this scenario instead of that normal fuction
is there is a diff ?
is that another way of factory pattern
too lazy to cut the last bit of this video off? lol same
I just use lamda variable in this case
Really useful feature for me.
Should have cut out the last second đ
Kotlin is the best language.
think that only Go is better đ€
@@mrjackson9137 I dont know go but I really love kotlin.
I still do not see the use of it being a nested function. Need to understand it better.
maybe when you need to execute repetitive code over a val declared inside the function itself i dunno
I imagine it'd be useful when you have some value in the scope of the parent function that you either don't want to calculate again in a regular class-level function or you simply can't because no other class-level functions would have access to that data. I've personally run into situations where this might've been useful but I tend to just use lambdas instead.
@@megaleuzao let me try write an example of this
Hmmm