Conclusion | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5429279-programming-in-swift-functions-and-types/lessons/19

Hi. FYI, the links to the course, book, swift algorithm club at the bottom of the video are broken (missing " : ")

1 Like

Thanks for letting me know! I’ve fixed the links :]

1 Like

The flatmap graphic at 1:20 is very confusing. Are you saying that flatmap transforms the elements of the array into something else? If I have an array that holds two arrays: [“Chicken”, “Cow”, “Egg”] and [“Potato”, “Apple”] the flat map should give you [“Chicken”, “Cow”, “Egg”, “Potato”, “Apple”] - not [“Drumstick”, “Burger”, “Fried Egg”, “Fries”, “Pie”].

I know this is silly, but clarity is so important when presenting a simple example.

flatMap, like map, can transform the elements if you use its closure to do that transformation.
But yes, if all you do with the closure is return the input, it’s base functionality would turn [“Chicken”, “Cow”, “Egg”] and [“Potato”, “Apple”] into [“Chicken”, “Cow”, “Egg”, “Potato”, “Apple”]

I see how the diagram can be misleading! Thanks for letting me know. Perhaps adding a a closure that makes it clear all the elements are being cooked would help.

Thanks for the reply catie.

I have always found map, filter, reduce, etc. explained poorly in the documentation and didn’t really understand them. However, you did a fantastic job in the video! I now can use them all. My recommendation for the example is go simple - don’t throw too many wrenches at us as we are getting up to speed. It does take a while to become comfortable with closure notation and usage.

Cheers!

(or, as you suggested, have a second example showing the power of closures and cooking the elements!)

1 Like