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

Комментарии • 177

  • @AlaaAlbrg
    @AlaaAlbrg 3 года назад +227

    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  3 года назад +10

      good!

    • @trungtrankim294
      @trungtrankim294 2 года назад +1

      Awesome. Thanks a lot man.

    • @rithulraj3348
      @rithulraj3348 Год назад +1

      *with()* is the combination of *let* and *run* because it does null check also, am I right?

    • @hazfrd
      @hazfrd Год назад +1

      @@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 3 года назад +62

    11:04 sick special effects bro
    .also {
    respect++
    }

  • @agp1444
    @agp1444 3 года назад +51

    also is very useful in case x = y.also { y = x } - switch values of variables without third variable

    • @mahdi7236
      @mahdi7236 2 года назад +1

      big brain time😉

    • @TheMohit987
      @TheMohit987 2 года назад

      😂😂😂😂 wow

    • @hieuluu2495
      @hieuluu2495 Год назад

      Awsome

    • @phamhung2263
      @phamhung2263 10 месяцев назад

      why don't we just switch those variables with a third variable. It's more readable

  • @ganshakumari5196
    @ganshakumari5196 2 года назад +2

    Fantastic explanation. Much clearer than most of the online resources, Thanks Mate!

  • @benjaminmorales8624
    @benjaminmorales8624 3 года назад +12

    You’re an amazing dev, thank you for all this effort and please keep it rocking!

  • @weather120widget8
    @weather120widget8 Год назад +2

    I really appreciate your teaching style, how you build on topics as you go. Keep up the great work.

  • @mirzasohailhussain
    @mirzasohailhussain 7 месяцев назад

    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

  • @damercy
    @damercy 3 года назад +13

    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! 🔥❤️

  • @TheMohit987
    @TheMohit987 2 года назад +1

    Your videos are very helpful. Your way of teaching is simply awesome.

  • @larrystreehouse1124
    @larrystreehouse1124 Год назад +1

    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 3 года назад +10

    Was literally just thinking about finally studying these, and you just uploaded. Thanks!

    • @iJuce
      @iJuce 3 года назад

      same wtf

    • @PhilippLackner
      @PhilippLackner  3 года назад +7

      yes, I can read your mind

    • @mz-coder
      @mz-coder 2 года назад

      @@PhilippLackner LOL!

  • @jackli1924
    @jackli1924 Год назад

    Awesome video!You explained very simply and concisely. Thanks a lot Philipp!

  • @achalbadgujar9519
    @achalbadgujar9519 3 года назад

    Finally a practically helpful explanation of these scope functions

  • @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.

  • @original_anu
    @original_anu 2 года назад

    Simple, crisp explanations ❤

  • @adarshdev3810
    @adarshdev3810 3 года назад

    It is awesome you explains concepts so simple. Hats off

  • @TheMaciak90
    @TheMaciak90 3 года назад

    Very well explained. Thank you mate.

  • @ianlipa9826
    @ianlipa9826 7 месяцев назад

    Your tutorials are a big help bro. Thanks!

  • @FatalRescue
    @FatalRescue 3 года назад +3

    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!

  • @ziakhan-tk7rk
    @ziakhan-tk7rk 2 года назад

    Your tutorials are addictive I watch them repeatedly

  • @carloscambon5402
    @carloscambon5402 9 месяцев назад

    You explain very clearly. Thank you.

  • @thearpansircar
    @thearpansircar 3 года назад +1

    An absolute psychic. I was going through Kotlin's Documentation and, suffice to say, it confused the fuck outta me.

  • @rahulchandrabhan
    @rahulchandrabhan 3 года назад

    One of the best explanation. Simple and Easy. Great man

  • @Aweklin
    @Aweklin 3 года назад

    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

  • @leosvxy
    @leosvxy 2 года назад

    thank you! , was so easy to understand your explanations

  • @EngDesper
    @EngDesper 2 года назад

    Thank you for the great explanation!

  • @salimmazariboufares3118
    @salimmazariboufares3118 2 года назад +1

    Cool, that was pretty much understandable by someone who is new to Kotlin.

  • @zareahmer5949
    @zareahmer5949 3 года назад

    You are Great man . Stay blessed

  • @imagetag4618
    @imagetag4618 3 года назад

    Wow. its so much clear understand. thank you. keep it up.

  • @Alvin-dg9pq
    @Alvin-dg9pq 3 года назад

    Fantastic explanation, thanks a lot.

  • @ramakrishnavjoshi
    @ramakrishnavjoshi 3 года назад

    Thanks for this video, Philipp. :)

  • @mahetachirag8395
    @mahetachirag8395 3 года назад

    Your tutorial are awesome.

  • @tanishqsehgal2593
    @tanishqsehgal2593 2 года назад

    Very Well Explained

  • @ajaykumarvishwakarma4720
    @ajaykumarvishwakarma4720 2 года назад

    Really informative video.
    Thanks a lot

  • @yuanyuechen2183
    @yuanyuechen2183 2 года назад

    Thank you, I really learn a lot from you

  • @FreeKnowledge
    @FreeKnowledge 2 года назад

    Fantastic explanation.

  • @yuripanov9670
    @yuripanov9670 2 года назад

    You're the best! Thanks!

  • @lyawileh.a8741
    @lyawileh.a8741 2 года назад

    Thanks for useful explanation. 🙏

  • @tomaslopez9999
    @tomaslopez9999 2 года назад

    Thanks for creating this video.

  • @techmarinar
    @techmarinar 2 года назад

    Thanx man this was very helpful 😊

  • @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.

  • @theonlyarjun
    @theonlyarjun 3 года назад

    just what i was searching for, awesome man

  • @koutheirelbehi4384
    @koutheirelbehi4384 3 года назад

    This boi is on another level !

  • @telurasinmontasik2406
    @telurasinmontasik2406 Год назад

    Very clear explanation

  • @indraj6669
    @indraj6669 3 года назад

    Great explanation

  • @marinbeslo7841
    @marinbeslo7841 2 года назад

    your tutorials are just awesome!

  • @r.j.jeninjoseph4975
    @r.j.jeninjoseph4975 3 года назад

    Really helpful thanks man

  • @anvarzaripboyev5730
    @anvarzaripboyev5730 Год назад

    Thanks bro, it is very usefull tutorial. Good luck!

  • @mdjahidulislam9205
    @mdjahidulislam9205 3 года назад +1

    I was waiting for it.you just read my mind

  • @themichael8767
    @themichael8767 Год назад

    Thank You very much, Sir!)

  • @tyrannus00
    @tyrannus00 Год назад

    Schönes Video, gut erklärt 👍

  • @jeffreyrudolph6334
    @jeffreyrudolph6334 Год назад

    so much better than the kotlin udacity explanations

  • @brucebane7401
    @brucebane7401 3 года назад

    amazing tutorial!!!!!

  • @dreamer6228751
    @dreamer6228751 3 года назад

    Thanks bro, it's excellent video !

  • @aunghtayoo337
    @aunghtayoo337 2 года назад

    Thanks. Philipp

  • @walkmn
    @walkmn 2 года назад

    Good explanation for the latest one 😄

  • @sckly43
    @sckly43 2 года назад

    awesome video bru

  • @alexnovikov1609
    @alexnovikov1609 Год назад

    Thank you!

  • @user-uu8rn6wf4u
    @user-uu8rn6wf4u Год назад

    Thank you!! 🤩

  • @Qrzychu92
    @Qrzychu92 2 года назад

    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#

  • @mohamadalighezelbashyan4482
    @mohamadalighezelbashyan4482 Год назад

    Great!! thanks ❤

  • @aneessaleh2870
    @aneessaleh2870 3 года назад +1

    amazing video mate , keep it up please

  • @leonidas_30052
    @leonidas_30052 3 года назад

    O melhor, muito bom os vídeos.

  • @imnithish
    @imnithish 3 года назад

    great vid as usual man

  • @mohammedelamin1563
    @mohammedelamin1563 3 года назад

    So helpful 😎

  • @RackaApps
    @RackaApps 3 года назад

    Super helpful

  • @vibinjoby
    @vibinjoby 2 года назад

    Amazing just what i wanted after reading the docs and wondering where exactly all these get used

  • @abuiman5251
    @abuiman5251 3 года назад

    Thanks!

  • @DeniizDenizDeniz
    @DeniizDenizDeniz 3 года назад +1

    How can you dislike this kind of tutorial 4 people? HOW?

  • @jayeshsuthar5590
    @jayeshsuthar5590 3 года назад

    crystal clear....

  • @fourcade7851
    @fourcade7851 3 года назад +1

    Thank You Bro

  • @mandroidx1474
    @mandroidx1474 3 года назад

    Appreciated
    Keep it up❤

  • @andriibibik39
    @andriibibik39 3 года назад

    Very Good!

  • @mehdiparsaei1867
    @mehdiparsaei1867 3 года назад

    The best in the world! I am sure!

  • @sudarshanh.s.521
    @sudarshanh.s.521 7 месяцев назад

    this is awesome

  • @pratikchauhan989
    @pratikchauhan989 3 года назад

    Good one 👏👏

  • @abdelsttarahmed8821
    @abdelsttarahmed8821 3 года назад

    you are legend man
    i wish seeing you doing a video on Providing offline capabilities with NetworkBoundResource

    • @PhilippLackner
      @PhilippLackner  3 года назад

      I do that in my ktor course on pl-coding.com

  • @shreyashachoudhary480
    @shreyashachoudhary480 Год назад

    Great!

  • @DreckbobBratpfanne
    @DreckbobBratpfanne 2 года назад +1

    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

  • @hirarkiardipratamakiki8777
    @hirarkiardipratamakiki8777 3 года назад

    i often use 'with 'to declare componen with viewbinding,such as onClickListener, and etc.

  • @DeepSingh-wk5ts
    @DeepSingh-wk5ts 3 года назад

    Thanks

  • @highs_and_lows4665
    @highs_and_lows4665 3 года назад

    This was explained very well. Udemy eat your heart out!😀 Many thanks!

  • @shidqi100
    @shidqi100 3 года назад

    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  3 года назад +1

      Not planned right now, but I also don't say I never will. I might do some flutter videos in the next time

  • @amiribrahim01
    @amiribrahim01 3 года назад

    thank you.

  • @shreyashchoudhary7413
    @shreyashchoudhary7413 3 года назад

    Epic!

  • @renaldyhiunarto4369
    @renaldyhiunarto4369 6 месяцев назад

    coming from the future and seeing you with beard kinda weird lmao. Anyway, love all your vids

  • @erfansn869
    @erfansn869 3 года назад

    thanks

  • @scottbiggs8894
    @scottbiggs8894 10 месяцев назад

    I never realized before that Philipp looks like the Elvis operator ?: ;)

  • @lional4898
    @lional4898 3 года назад

    With is useful when using string builder. No need to create new variables. Simply call toString at the end

  • @mohammadamirkanjoori138
    @mohammadamirkanjoori138 Год назад

    nice

  • @rsobies
    @rsobies 2 года назад

    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

  • @soontaek
    @soontaek 3 года назад

    I left you some feedback on your previous video (Preference Datastore)

  • @Alchemist10241
    @Alchemist10241 2 года назад

    This video definitely belongs to 5 percent group according to 95/5 rule (80/20 rule). Great and precise job 🚀

  • @ankitpareek8979
    @ankitpareek8979 Год назад

    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 !!!

  • @serhatkarakoca
    @serhatkarakoca 3 года назад

    Thanks for video.. Also i see use function. What is the use function? This is also scoped function

  • @Nithin_Coorg
    @Nithin_Coorg Год назад

    Crisp!

  • @MrLukasw44
    @MrLukasw44 Год назад

    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?

  • @ucPhamQuoc
    @ucPhamQuoc Год назад +1

    the beard is impressive

  • @vigneshdroid1654
    @vigneshdroid1654 Год назад

    Hi Bro, Your videos are very helpful for me. You Know Tamil language Bro?.

  • @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