Having a type defined for a closure's parameter type is not very readable. It might be made up of multiple types and/or instances of the same type repeated. That doesn't describe what it does. Learn how typealiases can help with that. Instead of having three parameters of type String, the typealias can name it something meaningful.
- [Instructor] So as we've been talking about types…for closures and functions, sometimes they can get a little…verbose, right?…So we've had some pretty simple functions so far so their…types have been string it, return string or int int…returns int, that's fine, but when you have three, four…types that are being passed in and their names…are a little bit longer, or if you have a bunch of the same…type like int, int, int, int, int returns string.…That's not very descriptive is it?…We're not really sure what each of those strings are…or what's being done.…
This is where type aliases can come in for these types…for closures and functions.…They specify the type without being so verbose and you can…use those in the parameter list and in the type…declarations instead of the long int string int returns int.…So let's look at an example.…So now we have a type alias called CombinesToStrings…and it defines the type string int return string.…So whereas before our uses string factory function…took a string int return string, now we can take…
- 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