In Swift 4.1, the flatMap function was divided into two functions. One kept the same name: flatMap This method flattens a sequence. Let’s say we have a two-dimensional array: let a = [[0,1,2],[3,4,5]] We can use the flatMap higher order function to ‘flatten’ this into a one-dimensional array: let b = a.flatMap{$0} //b = [0, 1, 2, 3, 4, 5] You could flatten a dictionary too – you would just need to
![flatMap vs compactMap](https://cdn-ak-scissors.b.st-hatena.com/image/square/2b3fca33424891af1042eed0496da384b4ccbaee/height=288;version=1;width=512/https%3A%2F%2Fcraiggrummitt.files.wordpress.com%2F2019%2F01%2Fcropped-grummitt-ios-hi.jpg%3Fw%3D200)