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

Поделиться
HTML-код
  • Опубликовано: 16 янв 2025

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

  • @AlaaAlbrg
    @AlaaAlbrg 4 года назад +241

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

      good!

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

      Awesome. Thanks a lot man.

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

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

    • @hazfrd
      @hazfrd 2 года назад +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 2 года назад

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

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

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

    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 2 года назад

      Awsome

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

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

    • @disgruntled_llama
      @disgruntled_llama 3 месяца назад

      @@phamhung2263 or write a function called "swapValues(x, y)" and use that. That's the most readable.

  • @damercy
    @damercy 4 года назад +14

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

  • @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 Год назад +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 4 года назад +10

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

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

      same wtf

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

      yes, I can read your mind

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

      @@PhilippLackner LOL!

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

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

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

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

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

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

  • @2chotti
    @2chotti 3 месяца назад

    This is the best video on scopes. Thanks

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

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

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

    Your tutorials are addictive I watch them repeatedly

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

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

  • @usherg4158
    @usherg4158 4 года назад

    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.

  • @rahimovdev
    @rahimovdev Месяц назад

    even so it was made 4 years ago , it's very useful that i've ever found

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

    Fantastic explanation.

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

    Finally a practically helpful explanation of these scope functions

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

    You explain very clearly. Thank you.

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

    Your tutorials are a big help bro. Thanks!

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

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

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

    Thanks for useful explanation. 🙏

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

    Very Well Explained

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

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

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

    Very clear explanation

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

    It is awesome you explains concepts so simple. Hats off

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

    I was waiting for it.you just read my mind

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

    You're the best! Thanks!

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

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

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

    Your tutorial are awesome.

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

    Thanks for creating this video.

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

    Simple, crisp 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

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

    Great explanation

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

    your tutorials are just awesome!

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

    Thank you for the great explanation!

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

    Thanx man this was very helpful 😊

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

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

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

    thank you! , was so easy to understand your explanations

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

    Thank you, I really learn a lot from you

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

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

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

    Good explanation for the latest one 😄

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

    Very well explained. Thank you mate.

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

    Really helpful thanks man

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

    just what i was searching for, awesome man

  • @VeronikaDoma-f5y
    @VeronikaDoma-f5y 2 года назад

    Thank you!! 🤩

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

    You are Great man . Stay blessed

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

    Really informative video.
    Thanks a lot

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

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

    Great!! thanks ❤

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

    Fantastic explanation, thanks a lot.

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

    The best in the world! I am sure!

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

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

    Thank You very much, Sir!)

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

    Thanks. Philipp

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

    Thank you!

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

    So helpful 😎

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

    amazing video mate , keep it up please

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

    so much better than the kotlin udacity explanations

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

    This boi is on another level !

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

    Thanks bro, it's excellent video !

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

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

    Schönes Video, gut erklärt 👍

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

    amazing tutorial!!!!!

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

    Thanks!

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

    great vid as usual man

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

    crystal clear....

  • @sudarshanh.s.521
    @sudarshanh.s.521 Год назад

    this is awesome

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

    Super helpful

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

    Thanks for this video, Philipp. :)

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

    awesome video bru

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

    Appreciated
    Keep it up❤

  • @cinemovieone
    @cinemovieone 4 года назад

    O melhor, muito bom os vídeos.

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

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

  • @fourcade7851
    @fourcade7851 4 года назад

    Thank You Bro

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

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

    Very Good!

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

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

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

    Good one 👏👏

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

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

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

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

    Great!

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

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

  • @thedeadserv
    @thedeadserv Месяц назад

    lol yo dude the beard! you can definitely make it work but clean is your jam :D tks for the video!

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

    the beard is impressive

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

    Shouldn't it be it++ instead of i++ at 6:19?

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

    thank you.

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

    thanks

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

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

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

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

    what is difference between return@let and simple return in let function

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

    👍🏻👍🏻👍🏻👍🏻👍🏻

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

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

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

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

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

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

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

    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

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

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

    Crisp!

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

    nice