Thank you lorentey!
I test performance this with my implementation as below
extension Dictionary {
public func compactMapValues<T>(_ transform: (Value) throws -> T?) rethrows -> [Key: T] {
return try self.reduce(into: [Key: T](), { (result, x) in
if let value = try transform(x.value) {
result[x.key] = value
}
})
}
}
Then I found latter is more faster so that I'll implement by mine and try to fix SPM too.