Avatar
アドバイスもらったの、投げてみました。ありがとうございます🙇‍♀️ https://forums.swift.org/t/pitch-add-compactmapvalues-to-dictionary/8741
Hi, I’d like to propose about compactMapValues in Dictionary. When I imagine removing nil value from dictionary at first as below, but it doesn’t works. "1" : "1", "2" : nil, "3" : "3"].flatMap { $0 } // [(key: "2", value: nil), (key: "1", value: Optional("1")), (key: "3", value: Optional("3"))] To avoid this, I’ve heard using reduce like this. let result = ["1": "1", "2": nil, "3": "3"].reduce(into: [String: String { (result, x) in if let value = x.value { result[x.key] = "(va...
👍 3