Check out example codes for "swift 5 flatMap wtih keypath". It will help you in understanding the concepts better.

Code Example 1

func flatMap<T>(_ keyPath: KeyPath<Element, [T]>) -> [T] {
    return self.flatMap { $0[keyPath: keyPath] }
}

let dependentItems = item.dependencies.flatMap(\.items)

Learn ReactJs, React Native from akashmittal.com