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.
@PhilippLackner4 жыл бұрын
good!
@trungtrankim2943 жыл бұрын
Awesome. Thanks a lot man.
@rithulraj33482 жыл бұрын
*with()* is the combination of *let* and *run* because it does null check also, am I right?
@hazfrd Жыл бұрын
@@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
@hazfrd Жыл бұрын
@@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()
@codinginflow4 жыл бұрын
11:04 sick special effects bro .also { respect++ }
@PhilippLackner4 жыл бұрын
pow(thanks, 10)
@johnybaby95744 жыл бұрын
Hi CiF~!
@codinginflow4 жыл бұрын
@@johnybaby9574 hi
@agp14443 жыл бұрын
also is very useful in case x = y.also { y = x } - switch values of variables without third variable
@mahdi72362 жыл бұрын
big brain time😉
@TheMohit9872 жыл бұрын
😂😂😂😂 wow
@hieuluu24952 жыл бұрын
Awsome
@phamhung2263 Жыл бұрын
why don't we just switch those variables with a third variable. It's more readable
@disgruntled_llama2 ай бұрын
@@phamhung2263 or write a function called "swapValues(x, y)" and use that. That's the most readable.
@damercy4 жыл бұрын
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! 🔥❤️
@PhilippLackner4 жыл бұрын
Thanks! You're totally welcome
@mirzasohailhussain Жыл бұрын
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
@larrystreehouse1124 Жыл бұрын
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.
@firuzaaliyeva53824 жыл бұрын
Was literally just thinking about finally studying these, and you just uploaded. Thanks!
@iJuce4 жыл бұрын
same wtf
@PhilippLackner4 жыл бұрын
yes, I can read your mind
@mz-coder3 жыл бұрын
@@PhilippLackner LOL!
@weather120widget8 Жыл бұрын
I really appreciate your teaching style, how you build on topics as you go. Keep up the great work.
@2chotti2 ай бұрын
This is the best video on scopes. Thanks
@benjaminmorales86244 жыл бұрын
You’re an amazing dev, thank you for all this effort and please keep it rocking!
@PhilippLackner4 жыл бұрын
Thanks, will do!
@ziakhan-tk7rk3 жыл бұрын
Your tutorials are addictive I watch them repeatedly
@rahimovdev14 күн бұрын
even so it was made 4 years ago , it's very useful that i've ever found
@ganshakumari51962 жыл бұрын
Fantastic explanation. Much clearer than most of the online resources, Thanks Mate!
@salimmazariboufares31183 жыл бұрын
Cool, that was pretty much understandable by someone who is new to Kotlin.
@TheMohit9872 жыл бұрын
Your videos are very helpful. Your way of teaching is simply awesome.
@thearpansircar4 жыл бұрын
An absolute psychic. I was going through Kotlin's Documentation and, suffice to say, it confused the fuck outta me.
@FatalRescue4 жыл бұрын
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!
@PhilippLackner4 жыл бұрын
yes, let > null-check
@ianlipa9826 Жыл бұрын
Your tutorials are a big help bro. Thanks!
@FreeKnowledge2 жыл бұрын
Fantastic explanation.
@carloscambon5402 Жыл бұрын
You explain very clearly. Thank you.
@tanishqsehgal25932 жыл бұрын
Very Well Explained
@usherg41583 жыл бұрын
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.
@achalbadgujar95194 жыл бұрын
Finally a practically helpful explanation of these scope functions
@telurasinmontasik24062 жыл бұрын
Very clear explanation
@indraj66693 жыл бұрын
Great explanation
@lyawileh.a87412 жыл бұрын
Thanks for useful explanation. 🙏
@rahulchandrabhan3 жыл бұрын
One of the best explanation. Simple and Easy. Great man
@PhilippLackner3 жыл бұрын
Glad you liked it
@adarshdev38103 жыл бұрын
It is awesome you explains concepts so simple. Hats off
@mahetachirag83953 жыл бұрын
Your tutorial are awesome.
@MyPhoneNotAccount Жыл бұрын
so much better than the kotlin udacity explanations
@aweklin4 жыл бұрын
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
@PhilippLackner4 жыл бұрын
Awesome, thank you!
@marinbeslo78413 жыл бұрын
your tutorials are just awesome!
@PhilippLackner3 жыл бұрын
Thanks a ton!
@walkmn2 жыл бұрын
Good explanation for the latest one 😄
@LittleWasteClub2 жыл бұрын
Thank you for the great explanation!
@rsobies3 жыл бұрын
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
@jackli1924 Жыл бұрын
Awesome video!You explained very simply and concisely. Thanks a lot Philipp!
@aneessaleh28704 жыл бұрын
amazing video mate , keep it up please
@PhilippLackner4 жыл бұрын
Thanks a lot!
@DreckbobBratpfanne2 жыл бұрын
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
@mdjahidulislam92054 жыл бұрын
I was waiting for it.you just read my mind
@PhilippLackner4 жыл бұрын
yes, I did
@anvarzaripboyev5730 Жыл бұрын
Thanks bro, it is very usefull tutorial. Good luck!
@Qrzychu923 жыл бұрын
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#
@tomaslopez99992 жыл бұрын
Thanks for creating this video.
@zareahmer59493 жыл бұрын
You are Great man . Stay blessed
@yuanyuechen21833 жыл бұрын
Thank you, I really learn a lot from you
@leosvxy3 жыл бұрын
thank you! , was so easy to understand your explanations
@imagetag46183 жыл бұрын
Wow. its so much clear understand. thank you. keep it up.
@TheMaciak903 жыл бұрын
Very well explained. Thank you mate.
@vibinjoby3 жыл бұрын
Amazing just what i wanted after reading the docs and wondering where exactly all these get used
@Alvin-dg9pq3 жыл бұрын
Fantastic explanation, thanks a lot.
@r.j.jeninjoseph49753 жыл бұрын
Really helpful thanks man
@original_anu3 жыл бұрын
Simple, crisp explanations ❤
@ajaykumarvishwakarma47203 жыл бұрын
Really informative video. Thanks a lot
@theonlyarjun4 жыл бұрын
just what i was searching for, awesome man
@PhilippLackner4 жыл бұрын
Glad to hear it!
@techmarinar3 жыл бұрын
Thanx man this was very helpful 😊
@yuripanov96703 жыл бұрын
You're the best! Thanks!
@hirarkiardipratamakiki87773 жыл бұрын
i often use 'with 'to declare componen with viewbinding,such as onClickListener, and etc.
@bjugdbjk3 жыл бұрын
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.
@PhilippLackner3 жыл бұрын
Thank you!
@koutheirelbehi43844 жыл бұрын
This boi is on another level !
@lional48984 жыл бұрын
With is useful when using string builder. No need to create new variables. Simply call toString at the end
@ankitpareek89792 жыл бұрын
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 !!!
@aunghtayoo3372 жыл бұрын
Thanks. Philipp
@mehdiparsaei18673 жыл бұрын
The best in the world! I am sure!
@tyrannus00 Жыл бұрын
Schönes Video, gut erklärt 👍
@MrLukasw442 жыл бұрын
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?
@mohityadav21 Жыл бұрын
Shouldn't it be it++ instead of i++ at 6:19?
@himanshugoeldelhi2 жыл бұрын
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
@dreamer62287514 жыл бұрын
Thanks bro, it's excellent video !
@PhilippLackner4 жыл бұрын
You're welcome!
@sckly433 жыл бұрын
awesome video bru
@abdelsttarahmed88214 жыл бұрын
you are legend man i wish seeing you doing a video on Providing offline capabilities with NetworkBoundResource
@PhilippLackner4 жыл бұрын
I do that in my ktor course on pl-coding.com
@imnithish4 жыл бұрын
great vid as usual man
@PhilippLackner4 жыл бұрын
Glad you enjoyed it
@themichael8767 Жыл бұрын
Thank You very much, Sir!)
@ucPhamQuoc Жыл бұрын
the beard is impressive
@alexnovikov1609 Жыл бұрын
Thank you!
@abhikhandelwal82533 жыл бұрын
All these Scope Functions are not showing in android studio ? it gives me an error and said make a external function for using these function why?
@ramakrishnavjoshi4 жыл бұрын
Thanks for this video, Philipp. :)
@nishantpattani30533 жыл бұрын
what is difference between return@let and simple return in let function
@serhatcd3 жыл бұрын
Thanks for video.. Also i see use function. What is the use function? This is also scoped function
@brucebane74013 жыл бұрын
amazing tutorial!!!!!
@shidqi1004 жыл бұрын
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?
@PhilippLackner4 жыл бұрын
Not planned right now, but I also don't say I never will. I might do some flutter videos in the next time
@mohammedelamin15633 жыл бұрын
So helpful 😎
@VeronikaDoma-f5y2 жыл бұрын
Thank you!! 🤩
@thedeadserv13 күн бұрын
lol yo dude the beard! you can definitely make it work but clean is your jam :D tks for the video!
@RackaApps3 жыл бұрын
Super helpful
@kor217272 жыл бұрын
I think 'with' is good in case of referring an object multi times. ex) binding.textA.text = "textA" binding.textB.text = "textB" ====> with(binding) { textA.text = "textA" testB.text = "textB" }
@PhilippLackner2 жыл бұрын
Same as apply
@tejas53313 жыл бұрын
Hey can you tell me how to fetch data about places from API and show on Map in Android?
@jasperjohnsoncalapini4 жыл бұрын
Can I do something else inside 'apply' and 'run' for example textbox.run { //is this a good practice val x = 10 val squareX = x*x // or maybe some loops text = "$x" } and one more thing, would you prefer 'apply' over 'run' when when modifying views/components in android? Thanks
@PhilippLackner4 жыл бұрын
no, I would move out of these functions whatever you can move out, this doesn't look very readable to me. If you just modify views and don't care about the return value it doesn't matter if you use apply or run
@ramakrishnavjoshi4 жыл бұрын
Why this does not product compile time error? var nullableField : String? = "" nullableField = "123" val nonNullableField : String = nullableField
@PhilippLackner4 жыл бұрын
Because the compiler is smart enough to see that nullableField is never null. Set it to null in between and it should give you an error
@ramakrishnavjoshi4 жыл бұрын
@@PhilippLackner Got your point but what if another thread assigns null to nullableField before it is used in third line? Edit: I think this is why there is a need to use let operator and consume `it`. Am I right?
@PhilippLackner4 жыл бұрын
@@ramakrishnavjoshi there is no way another thread can change it back to null in your scenario because the thread must be launched between the declaration of nullableField and nonNullableField and if you do that you get an compile error again. If you do the same, but declare nullableField globally you will get an error without setting it to null somewhere
@ramakrishnavjoshi4 жыл бұрын
@@PhilippLackner Got it. You summed up nicely. I was under wrong assumption that a nullableField can not be used to initialise nonNullableField.
@fourcade78514 жыл бұрын
Thank You Bro
@PhilippLackner4 жыл бұрын
No problem
@mohamadalighezelbashyan44822 жыл бұрын
Great!! thanks ❤
@coffeedude2 жыл бұрын
I learnt that you can use 'also' to swap variables but I don't understand why it works. ie: var foo = "foo" var bar = "bar" foo = bar.also { bar = foo } print(foo + bar) // barfoo
@soontaek4 жыл бұрын
I left you some feedback on your previous video (Preference Datastore)
@PhilippLackner4 жыл бұрын
Thanks, I saw it! :)
@vikasdaily1223 ай бұрын
How squaredFunctionI = (i*i) can be a function without return type and body.
@mandroidx14744 жыл бұрын
Appreciated Keep it up❤
@PhilippLackner4 жыл бұрын
Thank you, I will
@abuiman52513 жыл бұрын
Thanks!
@pratikchauhan9894 жыл бұрын
Good one 👏👏
@PhilippLackner4 жыл бұрын
Thanks ✌️
@riyupapa392 жыл бұрын
I usually use run like this var a:String?=null //When i want do something if only a is not null, a?.run{ //todo }
@scottbiggs8894 Жыл бұрын
I never realized before that Philipp looks like the Elvis operator ?: ;)