Discover how sort is a great example of a higher order function. There is a version of it for collections that takes no parameters. That's not a higher order function. But there is a version that does take a closure. It sorts the collection in place based on the comparison defined in the closure that returns true or false.
- [Instructor] So now, we're going to get our hands dirty…a little bit in Xcode.…So, we start up Xcode and I'm going to get started…with a playground.…I want to make sure it selects IOS and a blank playground.…And I will give it the default name of MyPlayground…and create it.…The first thing I'm going to do is delete the contents…and stop it from running.…Then I'm going to expand it to take the full screen.…I don't want it to run without me selecting it,…so, I'll hold this button down, this arrow button…in the bottom left, and select Manually Run.…
Now, I can tell it when to run, instead of it…just running all the time.…So, I'm going to start with a array of names…that we're going to sort.…So, I'll type on line one, var names equals,…and then I'm going to give it an array literal…of Bear, Kyle,…Jenna,…and Andrew.…Then, I want to sort these names.…So, I'll just call names.sort.…There's no return type…and I will print the names.…
So, there being no return type shows me that…it should sort the actual same array, and there it is.…
- What are closures?
- Closures and function types
- Basic higher-order functions, including sort and forEach
- Powerful higher-order functions, including map and reduce
- Passing functions
- Closure optimizations
- Higher-order functions on sets, dictionaries, and strings