flatMap and Terminal Operations
Learn about a few more functions and see their code visualizations.
flatMap
Another well-known function for collections is flatMap
. In the case of collections, it’s similar to a map, but the transformation function needs to return a collection that is then flattened. For example, if we have a list of departments, each of which has a list of employees, we can use flatMap
to make a list of all employees in all departments.
Get hands-on with 1400+ tech skills courses.