compactMap and flatMap: Clean Up Optionals and Crashes!

Поделиться
HTML-код
  • Опубликовано: 10 фев 2025
  • Both of these functions are super useful for reducing the nil checking in your programs. In this lesson I'll go over a couple of examples as to how and when to effectively integrate these functions into the logic of your applications. Enjoy.
    AppStore JSON APIs
    www.letsbuildt...
    Tinder Firestore Swipe and Match
    www.letsbuildt...
    Twitter Slide Out Menu Course
    www.letsbuildt...
    Podcasts Course
    www.letsbuildt...
    Intermediate Training Core Data
    www.letsbuildt...
    Instagram Firebase Course
    www.letsbuildt...
    Facebook Group
    / 1240636442694543
    Completed Source Code
    www.letsbuildt...
    Instagram: / buildthatapp
    Twitter: / buildthatapp
    Hackintosh Build
    i9 9900k: amzn.to/2CvQj6v
    ASUS Z390 Motherboard: amzn.to/2JpaQ2B
    16GB Corsair Vengeance RGB RAM: amzn.to/2YbygvJ
    Corsair H100i Platinum Water Cooler: amzn.to/2FnbM22
    Thermaltake RGB Power Supply: amzn.to/2TgKDTu
    Intel 1TB SSD: amzn.to/2Tkdk1V
    Corsair 280x Computer Case: amzn.to/2WcjvH2
    AMD Radeon 4GB RAM GFX Card: amzn.to/2TYMyAp
    LG 34" Widescreen 3440 x 1440: amzn.to/2Tk7q0S
    Rode NT1 Microphone: amzn.to/2TZgX1r
    Focusrite Audio Interface: amzn.to/2U12gey
    Panasonic GH4 DSLR: amzn.to/2U4BrG6
    Magewell HDMI to USB3 Capture Card: amzn.to/2Jp2esI

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

  • @bryanleebmy
    @bryanleebmy 5 лет назад +1

    map applies a transformation on each element before appending the result of that transformation to an output array.
    flatMap applies the transformation to the element, and concatenates the result of that transformation to each subsequent transformation.

  • @jensonjohn
    @jensonjohn 5 лет назад

    Thanks for the information

  • @maheshd7761
    @maheshd7761 5 лет назад

    Hey Brian. Fantastic stuff as always. I'm ready to download the app if you could put all your videos togather in. :)

  • @icode2206
    @icode2206 5 лет назад +1

    Good video bro

  • @smackaroony
    @smackaroony 5 лет назад

    grind never stops

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

    from 2021 and thanks!

  • @JunaidKhan-ny8tu
    @JunaidKhan-ny8tu 5 лет назад

    Cool video bro

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

    Thank you! :)

  • @davidkadlcek4949
    @davidkadlcek4949 5 лет назад +4

    When you use compactMap and then flatMap, is it not slow when you have a lot of data?

    • @puhgeh
      @puhgeh 5 лет назад +1

      exactly

    • @LetsBuildThatApp
      @LetsBuildThatApp  5 лет назад +2

      It's just a simple iteration over an array, how would it be different from a for loop?

    • @davidkadlcek4949
      @davidkadlcek4949 5 лет назад

      Is there any other solution to do that??

    • @bryanleebmy
      @bryanleebmy 5 лет назад +1

      Not sure what you mean by slow, as it is still O(n) time, which will hold true regardless of how you iterate through the elements.
      However, if you're concerned with processing each result as a stream of elements to be generated only when you need the element, you can look into .lazy . Lazy generation allows you to process elements downstream before continuing to process the subsequent elements in your stream. Do note that this will still be a sequential operation, but depending on your scenario it can be useful.

  • @bug18486
    @bug18486 5 лет назад

    Thanks Brain

  • @Yuurei
    @Yuurei 5 лет назад

    hey brian,please make another firebase backend bu with kotlin

    • @LetsBuildThatApp
      @LetsBuildThatApp  5 лет назад

      Didn't I do that already? Am I going crazy in 2019?

  • @MoAdel92
    @MoAdel92 5 лет назад

    Please can u help me how to watch ur content on ur RUclips channel
    From the noob part to the pro part
    Because i have just stared learning xcode and swift
    Thanks

    • @LetsBuildThatApp
      @LetsBuildThatApp  5 лет назад

      You’re probably on the wrong channel if you want newbie friendly content

    • @MoAdel92
      @MoAdel92 5 лет назад

      @@LetsBuildThatApp but i need ur guidance any how

  • @hambaadsense3506
    @hambaadsense3506 5 лет назад

    Hatur nuhun bro

  • @qiliou3386
    @qiliou3386 5 лет назад

    s.flatMap(transform) is equivalent to Array(s.map(transform).joined()).

  • @renjithgis5513
    @renjithgis5513 5 лет назад

    Can you please explain defer?

  • @david-tracy
    @david-tracy 5 лет назад

    Brian Voong!!!

  • @RobertoHernandez-op9fw
    @RobertoHernandez-op9fw 5 лет назад

    I didn't know compactMap handles optionals for you. That's awesome, but having to chain the mapping functions doesn't seem ideal since you have to make another pass over the array. I know this is just a simple example lol

    • @LetsBuildThatApp
      @LetsBuildThatApp  5 лет назад

      I feel like there's probably a better way around this issue that I'm not aware of but overall I like using this approach if it removes the code of nil checking.

  • @onurisk5617
    @onurisk5617 5 лет назад

    🎉👍🏻

  • @Omeir34
    @Omeir34 5 лет назад

    Second to comment