We look at the syntax for using Swift's built-in map function, compare it with the traditional procedural way, and then show some examples of how it can be used to improve our code.
[Instructor] The first of Swift's built-in functions…that we're going to be talking about is called Map.…Map is used when you want to take all the elements…in an array and convert them to some other value.…For example, if you wanted to double all the elements…in an array of numbers or convert an array…of inch measurements into an array…of centimeter measurements.…The way we do this is by calling Map on an array…and passing Map some function that we want to apply…to each element in the array.…Map then returns another array…that contains the return values…of the function for each element.…So, in other words, it takes each element…and maps it to the return value of the function we give it.…
If this function is something like square, for example,…we get an array where each of the numbers have been squared.…There is one thing that's important…to remember with the Map function…and most of Swift's built-in array functions.…In typical functional fashion,…it doesn't actually change the array we pass in.…It returns a copy.…
- What is functional programming?
- Keeping functions and data separate
- First-class functions
- Working with arrays functionally
- Filtering and reducing
- Partial-application and recursion
Skill Level Intermediate
Swift 4: Protocol-Oriented Programmingwith Károly Nyisztor1h 44m Intermediate
Swift: Delegations and Data Sourceswith Steven Lipton1h 6m Intermediate
Swift: Writing Reusable Frameworkswith David Okun1h 49m Intermediate
1. What Is Functional Programming?
2. First-Class Functions
3. Array Functions
4. Advanced Functional Concepts
Next steps1m 1s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.