Did You Know About THIS Kotlin Feature? 🤯

preview_player
Показать описание
Follow for more Android & Kotlin tips 🙌
Рекомендации по теме
Комментарии
Автор

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

asuras
Автор

Useful in Composable functions, when you do not want to pass many parameters to nested function

ryszardmachmudow
Автор

I like to use nested functions for helper functions that break up proceases without having to use comments.

ChrisAthanas
Автор

It's a pretty common pattern in compose

dies
Автор

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

mohegyux
Автор

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.

camilohernandezruiz
Автор

Interesting but still it looks wrong to me 😅, may be we need to get used to it

tatavarthitarun
Автор

It’s good for a cleaner code but you didn’t mention whether nested function able to access outer function’s local variables

iamwhoiam
Автор

what is better, lambas inside a function or nested functions?

darwinspace
Автор

Nice trick, I once had a scenario where this could be useful and was thinking if it's possible 😂

oubihinoureddine
Автор

too lazy to cut the last bit of this video off? lol same

Rin-qjzt
Автор

what about lamda functions i use it in this scenario instead of that normal fuction
is there is a diff ?

saifahmed
Автор

hi guys, in this case, why not use a lambda func?

franciscobneto
Автор

is that another way of factory pattern

yz
Автор

oh nice cool. ishlarizga omad . hamma video va contentlaringiz ajoyib va foydali.

azamovdev
Автор

I just use lamda variable in this case

bogdan.
Автор

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

antpr
Автор

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.

vinayrajagopal
Автор

I still do not see the use of it being a nested function. Need to understand it better.

ncba