Learn how dictionaries also implement higher order functions, but the closure parameter and return types might vary as compared to arrays. Usually the parameter of the closures is a tuple instead of a single item. The tuple will usually contain the key and value of the given dictionary item being passed in at the time.
- [Instructor] So now we're going to talk about…calling higher-order functions on Dictionaries.…So we talked about it on Arrays.…We talked about it on sets.…Now we're going to talk about it on Dictionaries.…So, the parameter that's passed into your closures…from a Dictionary higher-order function is a tuple.…We've talked a little bit about tuples.…On a Dictionary, it's simply two values: key and a value.…The things that are returned vary as we've seen before.…Filter returns a Dictionary…with the items filtered out of it.…
Sort returns an Array,…so you have to look at the return types.…Let's look at a couple examples.…So back in Xcode I'm going to delete everything.…Goodbye to our beloved names Array…and I'm going to create a new names.…"Let names =" but this is going to be a dictionary…so we have "LSU" and the name is "Tigers"…We have "UNT": "Eagles" these are the mascots…and then we have "UTEP" which is the "Miners"…as in digging in the ground not under a certain age.…
So now we're going to filter the names…so let one val or v1 equal "names.filter"…
- 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