We discuss how first-class functions in Swift allow us to return functions from other functions, and then show some examples of how to do so.
- [Man] So far we've seen that it's possible…to define functions in pretty much the same way…we define other things such as strings or integers.…And we've also seen that it's possible…to pass functions as arguments similar to other types.…So the next logical thing for us to look at…with first class functions,…is our ability to return functions from other functions.…Now, this is one of the places where the flexibility…of the first class functions give us…really starts to shine through.…Let's first look at the syntax for defining…a function that returns another function.…Since when we define functions,…we have to indicate what the return type is…by using an arrow and then a type.…
When we define a function that returns a function,…the type that we return is, as you may have guessed,…a function type.…So what if we want to create…a function that takes an integer,…and then returns another function…which doesn't take any arguments…and doesn't return anything?…That will look like this:…function, we'll call it return a function.…
- 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.