Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
How to use Dictionary.compactMapValues
Search
d_date
October 09, 2018
Programming
5k
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
How to use Dictionary.compactMapValues
potatotips #55
d_date
October 09, 2018
More Decks by d_date
See All by d_date
TCA Practice in 5 min
d_date
2
1.9k
waiwai-swiftpm-part2
d_date
3
600
わいわいSwift PM part 1
d_date
2
490
What's new in Firebase 2021
d_date
2
1.6k
CI/CDをミニマルに構築する
d_date
1
630
Swift Package centered project - Build and Practice
d_date
20
17k
How to write Great Proposal
d_date
4
2.4k
Thinking about Architecture for SwiftUI
d_date
8
2.5k
Integrate your app to modern world in Niigata
d_date
0
760
Other Decks in Programming
See All in Programming
業務時間外もAIに働いてもらう話
colorful12
3
9.9k
FastAPI の並行処理モデルを完全に理解する
hoto17296
9
3.7k
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
100
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
180
Swift愛好会100回記念 第1回を振り返る
jollyjoester
0
120
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.5k
kubernetes コンポーネント開発入門 / 新卒N年目の勉強会&交流会!〜〇〇への誘い〜 #n_study
mazrean
0
160
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
100
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
4.3k
20260828_品質と開発生産性を両立させる、AI時代のE2Eテストの考え方
magicpod
0
140
in-process GraphQL のすすめ #ginzajs
izumin5210
4
1.5k
「つくるAI」だけではバグは見つからない ~テストに必要な「見つけるAI」を分離させる戦略~
mfunaki
0
230
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
41
2.7k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
240
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
530
Utilizing Notion as your number one productivity tool
mfonobong
4
570
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
520
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Optimising Largest Contentful Paint
csswizardry
37
3.9k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
250
BBQ
matthewcrist
89
10k
Transcript
How to use Dictionary.compactMapValues potatotips #55 Daiki Matsudate / @d_date
Daiki Matsudate @d_date
https://peaks.cc/iOS_architecture
IUUQTZBLJSJOHPCPPUIQNJUFNT
Dictionary .compactMapValues
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 } }) } } Available in Swift 5
Use Cases
let d1 = ["a": "1", "b": "2", "c": nil] d1.filter({
$0.value != nil}).mapValues({ $0! }) // ["b": "2", "a": "1"]
["a": "1", "b": nil, "c": “3”].compactMapValues({ $0 }) // ["a"
: 1, "c" : 3]
var object = { 'a': 1, 'b': null, 'c': 3
}; _.omitBy(object, _.isNil); // => { 'a': 1, 'c': 3 } DG@PNJU#Z
let d = ["a": "1", "b": "2", "c": "three"] d.mapValues(Int.init).filter({
$0.value != nil}).mapValues({ $0! })
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 } }) } }
let d = ["a": "1", "b": "2", "c": "three"] d.compactMapValues(Int.init)
// ["b": 2, "a": 1]
None
• Daiki Matsudate / @d_date Available in Swift 5
Make our Swift better 09/05/2018 try! Swift NYC Daiki Matsudate
/ @d_date
None
• compactMapValues is available in Swift 5 • compactMapValues can
transform and unwrap dictionary • Let’s try to contribute to Swift lang Recap
None