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.
@@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()
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! 🔥❤️
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.
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.
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
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?
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
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
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?
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 !!!
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
You said "run" is the same as "with", but "with" is almost the same as "apply" isn't it? Because "with" and "apply" return expected types. run does not return. also { Thank you very much, it was a very informative video by the way. } :)
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
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
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
@@phamhung2263 or write a function called "swapValues(x, y)" and use that. That's the most readable.
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
Was literally just thinking about finally studying these, and you just uploaded. Thanks!
same wtf
yes, I can read your mind
@@PhilippLackner LOL!
You’re an amazing dev, thank you for all this effort and please keep it rocking!
Thanks, will do!
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
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.
I really appreciate your teaching style, how you build on topics as you go. Keep up the great work.
This is the best video on scopes. Thanks
Fantastic explanation. Much clearer than most of the online resources, Thanks Mate!
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
Cool, that was pretty much understandable by someone who is new to Kotlin.
Your videos are very helpful. Your way of teaching is simply awesome.
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.
Fantastic explanation.
Your tutorials are a big help bro. Thanks!
Finally a practically helpful explanation of these scope functions
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.
Awesome video!You explained very simply and concisely. Thanks a lot Philipp!
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!
It is awesome you explains concepts so simple. Hats off
One of the best explanation. Simple and Easy. Great man
Glad you liked it
Very clear explanation
I was waiting for it.you just read my mind
yes, I did
Thanks for useful explanation. 🙏
Very Well Explained
Simple, crisp explanations ❤
Thanks for creating this video.
Thanks bro, it is very usefull tutorial. Good luck!
Wow. its so much clear understand. thank you. keep it up.
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#
thank you! , was so easy to understand your explanations
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!
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
Very well explained. Thank you mate.
Thank you for the great explanation!
your tutorials are just awesome!
Thanks a ton!
Thank you, I really learn a lot from you
Your tutorial are awesome.
You are Great man . Stay blessed
Great explanation
so much better than the kotlin udacity explanations
Thanx man this was very helpful 😊
Good explanation for the latest one 😄
You're the best! Thanks!
amazing video mate , keep it up please
Thanks a lot!
Amazing just what i wanted after reading the docs and wondering where exactly all these get used
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
The best in the world! I am sure!
This boi is on another level !
Fantastic explanation, thanks a lot.
Schönes Video, gut erklärt 👍
Really informative video.
Thanks a lot
Really helpful thanks man
Thank You very much, Sir!)
Thanks for this video, Philipp. :)
awesome video bru
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
Thanks. Philipp
great vid as usual man
Glad you enjoyed it
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
Thanks bro, it's excellent video !
You're welcome!
So helpful 😎
Super helpful
coming from the future and seeing you with beard kinda weird lmao. Anyway, love all your vids
I never realized before that Philipp looks like the Elvis operator ?: ;)
Thank you!! 🤩
Thank you!
Thanks for video.. Also i see use function. What is the use function? This is also scoped function
amazing tutorial!!!!!
this is awesome
With is useful when using string builder. No need to create new variables. Simply call toString at the end
i often use 'with 'to declare componen with viewbinding,such as onClickListener, and etc.
Great!! thanks ❤
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
Thanks!
crystal clear....
Very Good!
Appreciated
Keep it up❤
Thank you, I will
O melhor, muito bom os vídeos.
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?
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 !!!
Great!
I left you some feedback on your previous video (Preference Datastore)
Thanks, I saw it! :)
Thank You Bro
No problem
Good one 👏👏
Thanks ✌️
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
You said "run" is the same as "with", but "with" is almost the same as "apply" isn't it? Because "with" and "apply" return expected types. run does not return. also {
Thank you very much, it was a very informative video by the way.
} :)
Epic!
I usually use run like this
var a:String?=null
//When i want do something if only a is not null,
a?.run{
//todo
}
Hey can you tell me how to fetch data about places from API and show on Map in Android?
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
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
Thanks
Welcome
what is difference between return@let and simple return in let function
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?