Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
How to use Dictionary.compactMapValues
Search
d_date
October 09, 2018
Programming
5.1k
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
2k
waiwai-swiftpm-part2
d_date
3
610
わいわいSwift PM part 1
d_date
2
500
What's new in Firebase 2021
d_date
2
1.6k
CI/CDをミニマルに構築する
d_date
1
640
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.6k
Integrate your app to modern world in Niigata
d_date
0
780
Other Decks in Programming
See All in Programming
PyConTW 2026 - AI Coding 不只是工具升級, 區域醫院醫療資訊系統協作開發與資訊團隊轉型實踐
cclai999
0
110
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
190
[2026-10-14](C)Re:ゼロから始める異世界生活〜始まりの終わりと終わりの始まり〜
tosite
0
140
dotNET_vulnclicker_intro.pdf
deka_morita
0
150
Verilogで学ぶCPU自作入門
uyuki234
8
4.2k
Long Living Tokens, Die, Die, Die! (or: The One Ring is Banned in Modern)
sylph01
0
340
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
3
660
JIS keyboard support in Omarchy
lef237
0
150
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
1k
Domain-Driven Transformation
hschwentner
2
2.3k
個人開発者よ、Honoを使え(おじさんver)
tanahiro2010
2
270
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
140
Featured
See All Featured
Building Applications with DynamoDB
mza
96
7.2k
Thoughts on Productivity
jonyablonski
76
5.4k
ラッコキーワード サービス紹介資料
rakko
2
5.4M
RailsConf 2023
tenderlove
30
1.6k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.4k
Writing Fast Ruby
sferik
630
63k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
600
Evolving SEO for Evolving Search Engines
ryanjones
0
330
Typedesign – Prime Four
hannesfritz
42
3.2k
From π to Pie charts
rasagy
1
400
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