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
Re: エラーと警告でコードをデザインする
Search
Yuka Ezura
March 22, 2017
Programming
2
940
Re: エラーと警告でコードをデザインする
Yuka Ezura
March 22, 2017
Tweet
Share
More Decks by Yuka Ezura
See All by Yuka Ezura
Mastering share sheet preview
ezura
4
1.3k
SF Symbols
ezura
9
1.2k
気遣いの iOS プログラミング
ezura
11
3.3k
Secret Swift tour
ezura
7
2.8k
Swift Album ver.4.1
ezura
3
1.4k
Swift と Kotlin
ezura
4
2.6k
哲学とSwiftの発表
ezura
5
580
アプリが動いたその先へ (iOS アプリ開発編)
ezura
1
950
Blending Kotlin's culture into Swift
ezura
1
1.2k
Other Decks in Programming
See All in Programming
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
660
Click-free releases & the making of a CLI app
oheyadam
2
110
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
ヤプリ新卒SREの オンボーディング
masaki12
0
130
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
Webの技術スタックで マルチプラットフォームアプリ開発を可能にするElixirDesktopの紹介
thehaigo
2
1k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Jakarta EE meets AI
ivargrimstad
0
590
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
Featured
See All Featured
Scaling GitHub
holman
458
140k
A Tale of Four Properties
chriscoyier
156
23k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Building Adaptive Systems
keathley
38
2.3k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Music & Morning Musume
bryan
46
6.2k
For a Future-Friendly Web
brad_frost
175
9.4k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Optimizing for Happiness
mojombo
376
70k
Transcript
Re: ΤϥʔͱܯࠂͰ ίʔυΛσβΠϯ͢Δ 2017/3/22 ezura
ςετ ։ൃମ੍ɾڥ ઃܭࢥɾཧ ݴޠʹΑΔ αϙʔτ j j j j ϜϲεϮϥᩆᕥ
https://speakerdeck.com/ezura/eratojing-gao-de-kodowodezainsuru-chi- tohuang-falselun-wu-qu ΤϥʔͱܯࠂͰίʔυΛσβΠϯ͢Δ NFUIPEṺ΅ᲇͩᘡᔀ͞ᩆ͖ͩͥͺΤ θϸϖΩϰᙉͽݕᒕͫΝ
લఏ struct Object { var name: String var something: Any
func common() { /* do something */ } func method1() { /* do something */ } func method2() { /* do something */ } }
method1 Λ࣮ߦ͔ͯ͠ΒͷΈ method2 Λ࣮ߦՄೳ (ҧΛίϯύΠϧ࣌ʹݕ) Mission1 // OK object.method1().method2() //
Error object.method2()
method1, method2 Λ࣮ߦޙͷ ΠϯελϯεͷΈҾͱͯ͠ड͚औΔؔ (ҧΛίϯύΠϧ࣌ʹݕ) Mission2 // OK accept(object.method1().method2()) //
Error accept(object.method2())
࣮
࣮ͷ֓೦ਤ instance Init state instance State1 instance State2 func method1
func method2
struct Object<State> { var name: String var something: Any func
common() { /* do something */ } }
extension Object where State: Init { func method1() -> Object<State1>
{ /* do something */ } } extension Object where State: State1 { func method2() -> Object<State2> { /* do something */ } } func accept(_ object: Object<State2>) { /* do something */ }
࣮ͷ֓೦ਤ instance Init state instance State1 instance State2 func method1
func method2 Object<Init> Object<State1> Object<State2>
ཧΘ͔ͬͨʂ ࣮ʹམͱ͠ࠐΜͰΈΑ͏
extension Object where State: Init { func method1() -> Object<State2>
{ let object = Object<State2>(…) // Object ͷϓϩύςΟΛҾ͖ܧ͗ return object } }
ܕύϥϝʔλ͕ҧ͏Πϯελϯε (= ҟͳΔܕ) ͷؒͰͲ͏ͬͯσʔλΛҾ͖ܧ͝͏…
Object<Init> ͔Β Object<State1> σʔλΛҾ͖ܧ͙ʹʁʁ new.name = self.name new.something =
self.something struct Container { var name: String var something: Any }
ΩϟετͰ͖ΔΑʂ ۽୩͞Μ
Object<Init> ͔Β Object<State1> extension Object where State: Init {
func method1() -> Object<State2> { let object = unsafeBitCast(self, to: Object<State2>.self) // do something return object } } Object<Init> ͔Β Object<State1> Cast
࣮Ͱ͖ͨʂ ͍উखͲ͏͔ͳʁʁ
let object = Object<Init>(name: "sample", something: "something") <Init> ͷ໌͕ࣔඞཁ… (´ɾωɾʆ)
ίϯύΠϥʹ͑ͯΈΑ͏
extension Object where State: Init { init(name: String, something: Any)
{ self.name = name self.something = something } } State ͕ Init ͷͱ͖ͷΈ ίϯετϥΫλΛએݴ
let object = Object(name: "sample", something: "something") <Init> ͷ໌͕ࣔෆཁ :
͜Ε͕ՄೳͱͳΔ͕݅͋Γ·ׂ͕͢Ѫ͠·͢ (͕݅ἧ͍ͬͯͳ͍߹ɺίϯύΠϧΤϥʔ)
ͱͬͯ៉ྷʹͳΓ·ͨ͠ʂʂ ٩( 'ω' )و
https://gist.github.com/ezura/ e71db2b0471285061f9700809f92f2b1 ίʔυ
ࢀর • ۽୩ͱ៸໘͕ϓϩάϥϛϯάίʔυͷ͔Βௌ͑ͯ͘͜ ΔʹࣖΛָ͚ͯ͠ΉϥδΦ #9, #14 http://mookmookradio.com/a0005/ • where Ͱͷܕਪͷఏএऀͷํͷ
gist https://gist.github.com/tarunon/ d7071689ab55e29bd367a44833687aa3 • ΤϥʔͱܯࠂͰίʔυΛσβΠϯ͢Δ https://speakerdeck.com/ezura/eratojing-gao-de- kodowodezainsuru-chi-tohuang-falselun-wu-qu