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.

Returning functions

Returning functions - Swift Tutorial

From the course: Learning Functional Programming with Swift

Start my 1-month free trial

Returning functions

- [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:…

Contents