Let, Also, Apply, Run, With - Kotlin Scope Functions

  Рет қаралды 99,650

Philipp Lackner

Philipp Lackner

Күн бұрын

Пікірлер: 181
@AlaaAlbrg
@AlaaAlbrg 4 жыл бұрын
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.
@PhilippLackner
@PhilippLackner 4 жыл бұрын
good!
@trungtrankim294
@trungtrankim294 3 жыл бұрын
Awesome. Thanks a lot man.
@rithulraj3348
@rithulraj3348 2 жыл бұрын
*with()* is the combination of *let* and *run* because it does null check also, am I right?
@hazfrd
@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
@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()
@codinginflow
@codinginflow 4 жыл бұрын
11:04 sick special effects bro .also { respect++ }
@PhilippLackner
@PhilippLackner 4 жыл бұрын
pow(thanks, 10)
@johnybaby9574
@johnybaby9574 4 жыл бұрын
Hi CiF~!
@codinginflow
@codinginflow 4 жыл бұрын
@@johnybaby9574 hi
@agp1444
@agp1444 3 жыл бұрын
also is very useful in case x = y.also { y = x } - switch values of variables without third variable
@mahdi7236
@mahdi7236 2 жыл бұрын
big brain time😉
@TheMohit987
@TheMohit987 2 жыл бұрын
😂😂😂😂 wow
@hieuluu2495
@hieuluu2495 2 жыл бұрын
Awsome
@phamhung2263
@phamhung2263 Жыл бұрын
why don't we just switch those variables with a third variable. It's more readable
@disgruntled_llama
@disgruntled_llama 2 ай бұрын
@@phamhung2263 or write a function called "swapValues(x, y)" and use that. That's the most readable.
@damercy
@damercy 4 жыл бұрын
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! 🔥❤️
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Thanks! You're totally welcome
@mirzasohailhussain
@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
@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.
@firuzaaliyeva5382
@firuzaaliyeva5382 4 жыл бұрын
Was literally just thinking about finally studying these, and you just uploaded. Thanks!
@iJuce
@iJuce 4 жыл бұрын
same wtf
@PhilippLackner
@PhilippLackner 4 жыл бұрын
yes, I can read your mind
@mz-coder
@mz-coder 3 жыл бұрын
@@PhilippLackner LOL!
@weather120widget8
@weather120widget8 Жыл бұрын
I really appreciate your teaching style, how you build on topics as you go. Keep up the great work.
@2chotti
@2chotti 2 ай бұрын
This is the best video on scopes. Thanks
@benjaminmorales8624
@benjaminmorales8624 4 жыл бұрын
You’re an amazing dev, thank you for all this effort and please keep it rocking!
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Thanks, will do!
@ziakhan-tk7rk
@ziakhan-tk7rk 3 жыл бұрын
Your tutorials are addictive I watch them repeatedly
@rahimovdev
@rahimovdev 14 күн бұрын
even so it was made 4 years ago , it's very useful that i've ever found
@ganshakumari5196
@ganshakumari5196 2 жыл бұрын
Fantastic explanation. Much clearer than most of the online resources, Thanks Mate!
@salimmazariboufares3118
@salimmazariboufares3118 3 жыл бұрын
Cool, that was pretty much understandable by someone who is new to Kotlin.
@TheMohit987
@TheMohit987 2 жыл бұрын
Your videos are very helpful. Your way of teaching is simply awesome.
@thearpansircar
@thearpansircar 4 жыл бұрын
An absolute psychic. I was going through Kotlin's Documentation and, suffice to say, it confused the fuck outta me.
@FatalRescue
@FatalRescue 4 жыл бұрын
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!
@PhilippLackner
@PhilippLackner 4 жыл бұрын
yes, let > null-check
@ianlipa9826
@ianlipa9826 Жыл бұрын
Your tutorials are a big help bro. Thanks!
@FreeKnowledge
@FreeKnowledge 2 жыл бұрын
Fantastic explanation.
@carloscambon5402
@carloscambon5402 Жыл бұрын
You explain very clearly. Thank you.
@tanishqsehgal2593
@tanishqsehgal2593 2 жыл бұрын
Very Well Explained
@usherg4158
@usherg4158 3 жыл бұрын
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.
@achalbadgujar9519
@achalbadgujar9519 4 жыл бұрын
Finally a practically helpful explanation of these scope functions
@telurasinmontasik2406
@telurasinmontasik2406 2 жыл бұрын
Very clear explanation
@indraj6669
@indraj6669 3 жыл бұрын
Great explanation
@lyawileh.a8741
@lyawileh.a8741 2 жыл бұрын
Thanks for useful explanation. 🙏
@rahulchandrabhan
@rahulchandrabhan 3 жыл бұрын
One of the best explanation. Simple and Easy. Great man
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Glad you liked it
@adarshdev3810
@adarshdev3810 3 жыл бұрын
It is awesome you explains concepts so simple. Hats off
@mahetachirag8395
@mahetachirag8395 3 жыл бұрын
Your tutorial are awesome.
@MyPhoneNotAccount
@MyPhoneNotAccount Жыл бұрын
so much better than the kotlin udacity explanations
@aweklin
@aweklin 4 жыл бұрын
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
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Awesome, thank you!
@marinbeslo7841
@marinbeslo7841 3 жыл бұрын
your tutorials are just awesome!
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Thanks a ton!
@walkmn
@walkmn 2 жыл бұрын
Good explanation for the latest one 😄
@LittleWasteClub
@LittleWasteClub 2 жыл бұрын
Thank you for the great explanation!
@rsobies
@rsobies 3 жыл бұрын
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
@jackli1924 Жыл бұрын
Awesome video!You explained very simply and concisely. Thanks a lot Philipp!
@aneessaleh2870
@aneessaleh2870 4 жыл бұрын
amazing video mate , keep it up please
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Thanks a lot!
@DreckbobBratpfanne
@DreckbobBratpfanne 2 жыл бұрын
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
@mdjahidulislam9205
@mdjahidulislam9205 4 жыл бұрын
I was waiting for it.you just read my mind
@PhilippLackner
@PhilippLackner 4 жыл бұрын
yes, I did
@anvarzaripboyev5730
@anvarzaripboyev5730 Жыл бұрын
Thanks bro, it is very usefull tutorial. Good luck!
@Qrzychu92
@Qrzychu92 3 жыл бұрын
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#
@tomaslopez9999
@tomaslopez9999 2 жыл бұрын
Thanks for creating this video.
@zareahmer5949
@zareahmer5949 3 жыл бұрын
You are Great man . Stay blessed
@yuanyuechen2183
@yuanyuechen2183 3 жыл бұрын
Thank you, I really learn a lot from you
@leosvxy
@leosvxy 3 жыл бұрын
thank you! , was so easy to understand your explanations
@imagetag4618
@imagetag4618 3 жыл бұрын
Wow. its so much clear understand. thank you. keep it up.
@TheMaciak90
@TheMaciak90 3 жыл бұрын
Very well explained. Thank you mate.
@vibinjoby
@vibinjoby 3 жыл бұрын
Amazing just what i wanted after reading the docs and wondering where exactly all these get used
@Alvin-dg9pq
@Alvin-dg9pq 3 жыл бұрын
Fantastic explanation, thanks a lot.
@r.j.jeninjoseph4975
@r.j.jeninjoseph4975 3 жыл бұрын
Really helpful thanks man
@original_anu
@original_anu 3 жыл бұрын
Simple, crisp explanations ❤
@ajaykumarvishwakarma4720
@ajaykumarvishwakarma4720 3 жыл бұрын
Really informative video. Thanks a lot
@theonlyarjun
@theonlyarjun 4 жыл бұрын
just what i was searching for, awesome man
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Glad to hear it!
@techmarinar
@techmarinar 3 жыл бұрын
Thanx man this was very helpful 😊
@yuripanov9670
@yuripanov9670 3 жыл бұрын
You're the best! Thanks!
@hirarkiardipratamakiki8777
@hirarkiardipratamakiki8777 3 жыл бұрын
i often use 'with 'to declare componen with viewbinding,such as onClickListener, and etc.
@bjugdbjk
@bjugdbjk 3 жыл бұрын
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.
@PhilippLackner
@PhilippLackner 3 жыл бұрын
Thank you!
@koutheirelbehi4384
@koutheirelbehi4384 4 жыл бұрын
This boi is on another level !
@lional4898
@lional4898 4 жыл бұрын
With is useful when using string builder. No need to create new variables. Simply call toString at the end
@ankitpareek8979
@ankitpareek8979 2 жыл бұрын
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 !!!
@aunghtayoo337
@aunghtayoo337 2 жыл бұрын
Thanks. Philipp
@mehdiparsaei1867
@mehdiparsaei1867 3 жыл бұрын
The best in the world! I am sure!
@tyrannus00
@tyrannus00 Жыл бұрын
Schönes Video, gut erklärt 👍
@MrLukasw44
@MrLukasw44 2 жыл бұрын
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
@mohityadav21 Жыл бұрын
Shouldn't it be it++ instead of i++ at 6:19?
@himanshugoeldelhi
@himanshugoeldelhi 2 жыл бұрын
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
@dreamer6228751
@dreamer6228751 4 жыл бұрын
Thanks bro, it's excellent video !
@PhilippLackner
@PhilippLackner 4 жыл бұрын
You're welcome!
@sckly43
@sckly43 3 жыл бұрын
awesome video bru
@abdelsttarahmed8821
@abdelsttarahmed8821 4 жыл бұрын
you are legend man i wish seeing you doing a video on Providing offline capabilities with NetworkBoundResource
@PhilippLackner
@PhilippLackner 4 жыл бұрын
I do that in my ktor course on pl-coding.com
@imnithish
@imnithish 4 жыл бұрын
great vid as usual man
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Glad you enjoyed it
@themichael8767
@themichael8767 Жыл бұрын
Thank You very much, Sir!)
@ucPhamQuoc
@ucPhamQuoc Жыл бұрын
the beard is impressive
@alexnovikov1609
@alexnovikov1609 Жыл бұрын
Thank you!
@abhikhandelwal8253
@abhikhandelwal8253 3 жыл бұрын
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?
@ramakrishnavjoshi
@ramakrishnavjoshi 4 жыл бұрын
Thanks for this video, Philipp. :)
@nishantpattani3053
@nishantpattani3053 3 жыл бұрын
what is difference between return@let and simple return in let function
@serhatcd
@serhatcd 3 жыл бұрын
Thanks for video.. Also i see use function. What is the use function? This is also scoped function
@brucebane7401
@brucebane7401 3 жыл бұрын
amazing tutorial!!!!!
@shidqi100
@shidqi100 4 жыл бұрын
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?
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Not planned right now, but I also don't say I never will. I might do some flutter videos in the next time
@mohammedelamin1563
@mohammedelamin1563 3 жыл бұрын
So helpful 😎
@VeronikaDoma-f5y
@VeronikaDoma-f5y 2 жыл бұрын
Thank you!! 🤩
@thedeadserv
@thedeadserv 13 күн бұрын
lol yo dude the beard! you can definitely make it work but clean is your jam :D tks for the video!
@RackaApps
@RackaApps 3 жыл бұрын
Super helpful
@kor21727
@kor21727 2 жыл бұрын
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" }
@PhilippLackner
@PhilippLackner 2 жыл бұрын
Same as apply
@tejas5331
@tejas5331 3 жыл бұрын
Hey can you tell me how to fetch data about places from API and show on Map in Android?
@jasperjohnsoncalapini
@jasperjohnsoncalapini 4 жыл бұрын
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
@PhilippLackner
@PhilippLackner 4 жыл бұрын
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
@ramakrishnavjoshi
@ramakrishnavjoshi 4 жыл бұрын
Why this does not product compile time error? var nullableField : String? = "" nullableField = "123" val nonNullableField : String = nullableField
@PhilippLackner
@PhilippLackner 4 жыл бұрын
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
@ramakrishnavjoshi
@ramakrishnavjoshi 4 жыл бұрын
@@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?
@PhilippLackner
@PhilippLackner 4 жыл бұрын
@@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
@ramakrishnavjoshi
@ramakrishnavjoshi 4 жыл бұрын
@@PhilippLackner Got it. You summed up nicely. I was under wrong assumption that a nullableField can not be used to initialise nonNullableField.
@fourcade7851
@fourcade7851 4 жыл бұрын
Thank You Bro
@PhilippLackner
@PhilippLackner 4 жыл бұрын
No problem
@mohamadalighezelbashyan4482
@mohamadalighezelbashyan4482 2 жыл бұрын
Great!! thanks ❤
@coffeedude
@coffeedude 2 жыл бұрын
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
@soontaek
@soontaek 4 жыл бұрын
I left you some feedback on your previous video (Preference Datastore)
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Thanks, I saw it! :)
@vikasdaily122
@vikasdaily122 3 ай бұрын
How squaredFunctionI = (i*i) can be a function without return type and body.
@mandroidx1474
@mandroidx1474 4 жыл бұрын
Appreciated Keep it up❤
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Thank you, I will
@abuiman5251
@abuiman5251 3 жыл бұрын
Thanks!
@pratikchauhan989
@pratikchauhan989 4 жыл бұрын
Good one 👏👏
@PhilippLackner
@PhilippLackner 4 жыл бұрын
Thanks ✌️
@riyupapa39
@riyupapa39 2 жыл бұрын
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
@scottbiggs8894 Жыл бұрын
I never realized before that Philipp looks like the Elvis operator ?: ;)
@andriibibik39
@andriibibik39 3 жыл бұрын
Very Good!
@jayeshsuthar5590
@jayeshsuthar5590 3 жыл бұрын
crystal clear....
@sudarshanh.s.521
@sudarshanh.s.521 Жыл бұрын
this is awesome
Make Your Code Clean With the SOLID Principles
18:24
Philipp Lackner
Рет қаралды 102 М.
Ozoda - Alamlar (Official Video 2023)
6:22
Ozoda Official
Рет қаралды 10 МЛН
Хаги Ваги говорит разными голосами
0:22
Фани Хани
Рет қаралды 2,2 МЛН
-5+3은 뭔가요? 📚 #shorts
0:19
5 분 Tricks
Рет қаралды 13 МЛН
Kotlin Scope Functions for Expressiveness: let, run, with, apply
24:51
Full Guide to Jetpack Compose Effect Handlers
24:56
Philipp Lackner
Рет қаралды 99 М.
How to Make Your Code Clean With Kotlin Sealed Classes
18:09
Philipp Lackner
Рет қаралды 41 М.
Kotlin Code Reuse: Composing like you're Inheriting
14:42
Dave Leeds
Рет қаралды 11 М.
MVVM vs. MVI - Understand the Difference Once and for All
18:40
Philipp Lackner
Рет қаралды 54 М.
Kotlin Coroutine (High-quality Course)
2:07:37
Smartherd
Рет қаралды 108 М.
CppCon 2014: Mike Acton "Data-Oriented Design and C++"
1:27:46
Ozoda - Alamlar (Official Video 2023)
6:22
Ozoda Official
Рет қаралды 10 МЛН