Let, Also, Apply, Run, With - Kotlin Scope Functions
HTML-код
- Опубликовано: 26 июл 2024
- In this video I will summarize for what you should choose which Kotlin scope function.
00:00 - Kotlin Scope Functions
00:30 - Let
05:10 - Also
07:20 - Apply
09:13 - Run
10:30 - With
⭐ Get certificates for your future job
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:
pl-coding.com/premium-courses...
💻 Let me personally review your code and provide individual feedback, so it won't backfire and cost you a fortune in future:
elopage.com/s/philipplackner/...
Regular Android tutorials on my Instagram: / _philipplackner_
Checkout my GitHub: github.com/philipplackner
Summary of Scope functions:
let: Used to check nulls, also better than simple null check in multi-threading case
also: same as 'let' but it doesn't return the last line as 'let', instead 'also' will return the object it was called on and 'not the last line!'
apply: helpful function to modify objects, if you want to change in properties of the objects, and it uses 'this' instead of 'it' as we work inside the class of the object
run: equivalent to 'apply', but it won't return the object it was called, instead it will return the last line
with: same as 'run' but a different signature.
good!
Awesome. Thanks a lot man.
*with()* is the combination of *let* and *run* because it does null check also, am I right?
@@rithulraj3348 nope. In fact run is combination of with & let. Run does check nullpointer (let) and reference with this (with) , after that return the last line a.k.a lambda expression
@@rithulraj3348 with() doesn't checking null, just for non-null. in case it is null then use let(), in case you want make some operation while checking null then use run()
11:04 sick special effects bro
.also {
respect++
}
pow(thanks, 10)
Hi CiF~!
@@johnybaby9574 hi
also is very useful in case x = y.also { y = x } - switch values of variables without third variable
big brain time😉
😂😂😂😂 wow
Awsome
why don't we just switch those variables with a third variable. It's more readable
Fantastic explanation. Much clearer than most of the online resources, Thanks Mate!
You’re an amazing dev, thank you for all this effort and please keep it rocking!
Thanks, will do!
I really appreciate your teaching style, how you build on topics as you go. Keep up the great work.
Thanks Philip, you are sharing so much knowledge without any charge. I have seen so many people share only basics and then member only videos
Hey man. I just learnt Kotlin. Previously I've made a few basic projects in android using Java. Fortunately,I found your channel with some really good resources to learn android dev in Kotlin. Just wanted to say a genuine thank you for putting out such great content. Please don't stop. Power to you! 🔥❤️
Thanks! You're totally welcome
Your videos are very helpful. Your way of teaching is simply awesome.
Simple and Concise explanation. Even though I go self-learning with Kotlin for 1 year, this is great to recall my memory and consolidate my knowledge. More importantly, you show us how to teach and explain the basic concept in an interesting and concise passages with live examples.
Was literally just thinking about finally studying these, and you just uploaded. Thanks!
same wtf
yes, I can read your mind
@@PhilippLackner LOL!
Awesome video!You explained very simply and concisely. Thanks a lot Philipp!
Finally a practically helpful explanation of these scope functions
o man, I have been reading lots of explanation and still not get it until watching yours. Great example and explanation, thanks for making this video.
Simple, crisp explanations ❤
It is awesome you explains concepts so simple. Hats off
Very well explained. Thank you mate.
Your tutorials are a big help bro. Thanks!
Wow, thank you for opening my eyes. I was just using let as shorthand for the null check and did not realize how useful it actually is!
yes, let > null-check
Your tutorials are addictive I watch them repeatedly
You explain very clearly. Thank you.
An absolute psychic. I was going through Kotlin's Documentation and, suffice to say, it confused the fuck outta me.
One of the best explanation. Simple and Easy. Great man
Glad you liked it
I already liked the video before watching because it is the topic I had pinned on my todo list to research this week.
Thanks Philipp
Awesome, thank you!
thank you! , was so easy to understand your explanations
Thank you for the great explanation!
Cool, that was pretty much understandable by someone who is new to Kotlin.
You are Great man . Stay blessed
Wow. its so much clear understand. thank you. keep it up.
Fantastic explanation, thanks a lot.
Thanks for this video, Philipp. :)
Your tutorial are awesome.
Very Well Explained
Really informative video.
Thanks a lot
Thank you, I really learn a lot from you
Fantastic explanation.
You're the best! Thanks!
Thanks for useful explanation. 🙏
Thanks for creating this video.
Thanx man this was very helpful 😊
Such a fab explanation, Thanks a ton, You should really do a lot more this kind of standalone videos of advanced concepts of Kotlin, it will b super helpful.
Thank you!
just what i was searching for, awesome man
Glad to hear it!
This boi is on another level !
Very clear explanation
Great explanation
your tutorials are just awesome!
Thanks a ton!
Really helpful thanks man
Thanks bro, it is very usefull tutorial. Good luck!
I was waiting for it.you just read my mind
yes, I did
Thank You very much, Sir!)
Schönes Video, gut erklärt 👍
so much better than the kotlin udacity explanations
amazing tutorial!!!!!
Thanks bro, it's excellent video !
You're welcome!
Thanks. Philipp
Good explanation for the latest one 😄
awesome video bru
Thank you!
Thank you!! 🤩
I don't even programm in Kotlin (fellow dotnet dev here!), but this videos are very cool :) I'd love to have this tuff in C#
Great!! thanks ❤
amazing video mate , keep it up please
Thanks a lot!
O melhor, muito bom os vídeos.
great vid as usual man
Glad you enjoyed it
So helpful 😎
Super helpful
Amazing just what i wanted after reading the docs and wondering where exactly all these get used
Thanks!
How can you dislike this kind of tutorial 4 people? HOW?
crystal clear....
Thank You Bro
No problem
Appreciated
Keep it up❤
Thank you, I will
Very Good!
The best in the world! I am sure!
this is awesome
Good one 👏👏
Thanks ✌️
you are legend man
i wish seeing you doing a video on Providing offline capabilities with NetworkBoundResource
I do that in my ktor course on pl-coding.com
Great!
i liked to use with eg in viewbinding, because then i can avoid typing the binding variable name xD, also you can use multiple of them within each other what is also pretty nifty
i often use 'with 'to declare componen with viewbinding,such as onClickListener, and etc.
Thanks
Welcome
This was explained very well. Udemy eat your heart out!😀 Many thanks!
Great video expected man love your explanation, just asking will you make videos outside topic of android and mobile dev in general ex: Ai, web or desktop?
Not planned right now, but I also don't say I never will. I might do some flutter videos in the next time
thank you.
Welcome!
Epic!
coming from the future and seeing you with beard kinda weird lmao. Anyway, love all your vids
thanks
Welcome
I never realized before that Philipp looks like the Elvis operator ?: ;)
With is useful when using string builder. No need to create new variables. Simply call toString at the end
nice
in this case number is a property so it is a function. a function can return different results and that's why it is considered as mutuable. inside let block you are dealing directly with a field of the class. 'it' is a field, not a property. so it is immutable
I left you some feedback on your previous video (Preference Datastore)
Thanks, I saw it! :)
This video definitely belongs to 5 percent group according to 95/5 rule (80/20 rule). Great and precise job 🚀
I have an usecase where i need to call a suspend function(some network call) on completion of it i need to perform other local task. I am trying to use also there but getting unexpected results. Can u explain this !!!
Thanks for video.. Also i see use function. What is the use function? This is also scoped function
Crisp!
but is that mean that apply is thread safe? so if we got an object and we would like to run 3 methods on that object and that object is a global variable so the question is if we use apply those 3 operations will be thread safe?
the beard is impressive
Hi Bro, Your videos are very helpful for me. You Know Tamil language Bro?.
Try executing that code if some people don't understand what 'let' does
number?.let {
number = null
val num2 = it + 1
}
Here 'let' actually saved the global value of number and even in case number becomes null in 'let' block , still 'it' value will remain the same which you defined before