From the course: Learning Functional Programming with Swift
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Function types - Swift Tutorial
From the course: Learning Functional Programming with Swift
Function types
- [Instructor] As I mentioned before, functional programming's treatment of functions as first-class citizens means that we can treat functions in a very similar way to other types, such as strings, numbers, or objects. The first thing we're going to look at is an alternative way of defining functions. In Swift, the way most of us are probably used to defining functions is using the func keyword. And the fact is that this is a perfectly fine way to do it. But there's also another way that we can define functions, and it has a syntax that's more similar to the way we define variables and constants. So when we define a constant such as a string or an integer, the basic syntax looks like this, where the type that we put after the colon, in this case string or int, denotes the type of our variables. We can also define a function in this way, but if we do so, what does the type look like? Well, to answer this, we need to ask ourselves, what types of arguments the function takes, and what…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.