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
enum as Option.
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
r-plus
June 21, 2018
Technology
0
2.3k
enum as Option.
enum as Option.
potatotips #52
r-plus
June 21, 2018
Tweet
Share
More Decks by r-plus
See All by r-plus
Swizzling Swizzling Swizzling
r_plus
0
410
Image optimization for mobile on CDN
r_plus
0
680
Advanced guard of DeallocationChecker
r_plus
2
3.2k
東急ハンズの P2Pレジ間通信2018
r_plus
4
2.1k
Enterprise cert management.
r_plus
0
400
CircleCI 2.0 for macOS
r_plus
1
1.3k
carthage verify
r_plus
2
5.9k
業務アプリの切札 Programable KIOSK mode 大全
r_plus
0
4.3k
PropertyObserverとinoutでやらかした話
r_plus
1
1.3k
Other Decks in Technology
See All in Technology
Master Dataグループ紹介資料
sansan33
PRO
1
4.2k
GitHub Copilot CLI 現状確認会議
torumakabe
12
3.8k
Riverpod3.xで実現する実践的UI実装
fumiyasac0921
1
300
Exadata Database Service ソフトウェアのアップデートとアップグレードの概要
oracle4engineer
PRO
1
1.2k
これまでのネットワーク運用を変えるかもしれないアプデをおさらい
hatahata021
4
270
研究開発部メンバーの働き⽅ / Sansan R&D Profile
sansan33
PRO
4
22k
ソフトとハード両方いけるデータ人材の育て方
waiwai2111
1
550
Databricks Free Edition講座 データエンジニアリング編
taka_aki
0
2.8k
Kusakabe_面白いダッシュボードの表現方法
ykka
0
370
CodeRabbit CLI + Claude Codeの連携について
oikon48
1
590
AI Agent Agentic Workflow の可観測性 / Observability of AI Agent Agentic Workflow
yuzujoe
5
2.3k
フロントエンド開発者のための「厄払い」
optim
0
120
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
How to Think Like a Performance Engineer
csswizardry
28
2.4k
Test your architecture with Archunit
thirion
1
2.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.7k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
9.8k
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
49
The agentic SEO stack - context over prompts
schlessera
0
600
A designer walks into a library…
pauljervisheath
210
24k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
61
49k
It's Worth the Effort
3n
188
29k
Transcript
FOVN BT0QUJPO 6/21 potatotips #52 taiki komaba(@r_plus)
UBJLJLPNBCB !S@QMVT
0QUJPO4FU
CJUຖʹΦϓγϣϯΛׂͯΔ ΦϓγϣϯͷͨΊͷͷͬΆ͍
public extension DispatchQueue { public struct Attributes : OptionSet {
public let rawValue: UInt64 public init(rawValue: UInt64) { self.rawValue = rawValue } public static let concurrent = Attributes(rawValue: 1<<1) @available(macOS 10.12, iOS 10.0, tvOS 10.0, watchOS 3.0, *) public static let initiallyInactive = Attributes(rawValue: 1<<2) … 'PVOEBUJPOͰ Α͘ΘΕ͍ͯΔ https://github.com/apple/swift/blob/master/stdlib/public/SDK/Dispatch/Queue.swift
struct ShippingOptions: OptionSet { let rawValue: Int static let nextDay
= ShippingOptions(rawValue: 1 << 0) static let secondDay = ShippingOptions(rawValue: 1 << 1) static let priority = ShippingOptions(rawValue: 1 << 2) static let standard = ShippingOptions(rawValue: 1 << 3) } ࣮͢Δͱ͜͏ͳΔ
self.doSomething(arg, option: [.nextDay, .priority]) … func doSomething(_ arg: Any, option:
ShippingOptions) { … } ͏ଆ͜͏
func doSomething(_ arg: Any, option: ShippingOptions) { if option.contains(.nextDay) {
… } if option.contains(. secondDay) { … } } ͰɺͲͷΦϓγϣϯ͕ࢦఆ͞Ε͔ͨͰ ڍಈΛม͑Δʜ
None
ͳΜ͔Φϓγϣϯఆ͍͚ͨͩ͠ʹͯ͠ هड़͕໘͡Όͳ͍ʁ struct ShippingOptions: OptionSet { let rawValue: Int static
let nextDay = ShippingOptions(rawValue: 1 << 0) static let secondDay = ShippingOptions(rawValue: 1 << 1) static let priority = ShippingOptions(rawValue: 1 << 2) static let standard = ShippingOptions(rawValue: 1 << 3) }
struct ShippingOptions: OptionSet { let rawValue: Int static let nextDay
= ShippingOptions(rawValue: 1 << 0) static let secondDay = ShippingOptions(rawValue: 1 << 1) static let priority = ShippingOptions(rawValue: 1 << 2) static let standard = ShippingOptions(rawValue: 1 << 3) } ͳΜ͔Φϓγϣϯఆ͍͚ͨͩ͠ʹͯ͠ هड़͕໘͡Όͳ͍ʁ ͜ͷ͋ͨΓ͕ɻ
FOVNͰͬͯΈΑ͏
0QUJPOఆٛˠγϯϓϧFOVN enum ShippingOptions { case nextDay case secondDay case priority
case standard }
self.doSomething(arg, option: .nextDay) … func doSomething(_ arg: Any, option: ShippingOptions)
{ … } ͏ଆ͕͜͏
͜ͷ··ͩͱ ෳΦϓγϣϯࢦఆ͕ग़དྷͳ͍ͷͰʜ
ՄมҾ ʢ7BSJBEJD1BSBNFUFSTʣ
͜͏ͩͬͨͷΛ self.doSomething(arg, option: .nextDay) … func doSomething(_ arg: Any, option:
ShippingOptions) { … }
self.doSomething(arg, option: .nextDay, . priority) … Մมʹ͢Δ func doSomething(_ arg:
Any, option: ShippingOptions…) {…}
func doSomething(_ arg: Any, option: ShippingOptions…) { if option.contains(.nextDay) {
… } if option.contains(. secondDay) { … } } ࣮ଆʹ"SSBZ͕དྷΔͷͰมߋͳ͠
·ͱΊ ϝιουͷΦϓγϣϯΛ ؆୯ʹఆ͍͚ٛͨͩ͠Ͱ͋ΕΞϦͳͷͰ
͓ΘΓɻ