We look at the syntax for using Swift's built-in filter function, and then compare it with the traditional procedural way.
- [Instructor] The next important built-in array function…is called filter.…Filter is used when you want to extract…all of the elements in an array…that fit some kind of criteria.…For example, if we have an array of numbers…and we want to get all the numbers from it…that are even.…Or if we have an array of employee data…and we want to find the employees from this array…that make more than a certain amount per year.…These are things that filter can help us with.…The syntax of filter is similar to map.…We can call it on any array…and then we pass in a function.…The main difference between filter and map is the type…of function that we pass into it.…
In map, we pass in a function that returns a value…for each element in an array.…The return value of this function represents…what an element becomes in our new array.…On the other hand for filter,…we pass in a function…that returns either true or false for each element.…If the function that we pass returns true…for a given element,…then the element is included in the final array.…
Author
Released
5/16/2018- 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
Duration
Views
Related Courses
-
Swift 4 Essential Training
with Harrison Ferrone3h 15m Beginner -
Swift 4: Protocol-Oriented Programming
with Károly Nyisztor1h 44m Intermediate -
Swift: Delegations and Data Sources
with Steven Lipton1h 6m Intermediate -
Swift: Writing Reusable Frameworks
with David Okun1h 49m Intermediate -
Swift: Writing Testable Code
with Mark DiFranco3h 11m Intermediate
-
Introduction
-
Welcome55s
-
-
1. What Is Functional Programming?
-
2. First-Class Functions
-
Function types2m 14s
-
Returning functions5m 59s
-
-
3. Array Functions
-
Mapping57s
-
Mapping example3m 41s
-
Filtering57s
-
Filtering example3m 2s
-
Reducing27s
-
Reducing example3m 36s
-
4. Advanced Functional Concepts
-
Advanced concepts1m 1s
-
Partial application3m 47s
-
Recursion3m 6s
-
-
Conclusion
-
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.
CancelTake 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.
Share this video
Embed this video
Video: Filtering