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
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.8k
waiwai-swiftpm-part2
d_date
3
570
わいわいSwift PM part 1
d_date
2
450
What's new in Firebase 2021
d_date
2
1.6k
CI/CDをミニマルに構築する
d_date
1
620
Swift Package centered project - Build and Practice
d_date
20
16k
How to write Great Proposal
d_date
4
1.9k
Thinking about Architecture for SwiftUI
d_date
8
2.5k
Integrate your app to modern world in Niigata
d_date
0
720
Other Decks in Programming
See All in Programming
Understanding Apache Lucene - More than just full-text search
spinscale
0
150
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
350
飯MCP
yusukebe
0
440
Codex の「自走力」を高める
yorifuji
0
1.3k
AI時代の脳疲弊と向き合う ~言語学としてのPHP~
sakuraikotone
1
1.7k
Tamach-sre-3_ANDPAD-shimaison93
mane12yurks38
0
210
ネイティブアプリとWebフロントエンドのAPI通信ラッパーにおける共通化の勘所
suguruooki
0
230
20260320登壇資料
pharct
0
140
ポーリング処理廃止によるイベント駆動アーキテクチャへの移行
seitarof
3
1.3k
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
160
OTP を自動で入力する裏技
megabitsenmzq
0
130
Codex CLIのSubagentsによる並列API実装 / Parallel API Implementation with Codex CLI Subagents
takatty
2
730
Featured
See All Featured
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
440
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
140
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
68
38k
Balancing Empowerment & Direction
lara
5
1k
Art, The Web, and Tiny UX
lynnandtonic
304
21k
Claude Code のすすめ
schroneko
67
220k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
The agentic SEO stack - context over prompts
schlessera
0
720
Design in an AI World
tapps
0
190
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.1k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
260
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