swift 5 flatMap wtih keypath code example
Example: swift 5 flatMap wtih keypath
func flatMap<T>(_ keyPath: KeyPath<Element, [T]>) -> [T] {
return self.flatMap { $0[keyPath: keyPath] }
}
let dependentItems = item.dependencies.flatMap(\.items)
func flatMap<T>(_ keyPath: KeyPath<Element, [T]>) -> [T] {
return self.flatMap { $0[keyPath: keyPath] }
}
let dependentItems = item.dependencies.flatMap(\.items)