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
Swiftのmapからその次へ
Search
oyuk
August 04, 2016
Programming
1
1.3k
Swiftのmapからその次へ
oyuk
August 04, 2016
Tweet
Share
More Decks by oyuk
See All by oyuk
Shorebird について
oyuk
0
330
Material designのWindow size classについて
oyuk
0
950
Swiftでなんで[weak self]するのか?
oyuk
2
4.6k
LLVMについて調べた
oyuk
0
170
Other Decks in Programming
See All in Programming
Re:ProS_案内資料
rect
0
360
Nuxtベースの「WXT」でChrome拡張を作成する | Vue Fes 2024 ランチセッション
moshi1121
1
410
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
140
現場で役立つモデリング 超入門
masuda220
PRO
12
2.8k
Importmapを使ったJavaScriptの 読み込みとブラウザアドオンの影響
swamp09
4
1.2k
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
230
Prompt Engineering for Developers @ AWS Community Day Adria 2024
slobodan
0
120
ECSのサービス間通信 4つの方法を比較する 〜Canary,Blue/Greenも添えて〜
tkikuc
10
2.3k
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
470
カスタムしながら理解するGraphQL Connection
yanagii
1
1.1k
Vue3の一歩踏み込んだパフォーマンスチューニング2024
hal_spidernight
3
3.1k
Why Spring Matters to Jakarta EE - and Vice Versa
ivargrimstad
0
790
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
9
670
Art, The Web, and Tiny UX
lynnandtonic
296
20k
Designing the Hi-DPI Web
ddemaree
280
34k
Become a Pro
speakerdeck
PRO
24
5k
We Have a Design System, Now What?
morganepeng
50
7.2k
How GitHub (no longer) Works
holman
311
140k
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
7
150
Transcript
Swiftͷmap͔Βͦͷ࣍ 2016/08/04 oyuk(@oydku)
ࣗݾհ • oyuk(@oydku) • iosΞϓϦΤϯδχΞ!
Swiftͷmap map͕͑ΔͭΒ͍͔ͭ͋͘ΔΑͶ • Optional (Enum) • Array (CollectionType) • ObservableType
(RxSwift) ଞʹ͔͋ͬͨͶɻ͋ͬͨΒڭ͑ͯ
mapͷఆٛΛݟΔ Optional func map<U>(@noescape f: (Wrapped) throws -> U) rethrows
-> U? Array func map<T>(@noescape transform: (Self.Generator.Element) throws -> T) rethrows -> [T] ObservableType public func map<R>(selector: Self.E throws -> R) -> RxSwift.Observable<R>
ڞ௨͋ΔΑͶ!
͍͍ͩͨ͜Μͳײ͡ func map<U>(f:T -> U) -> ͋Δ<U>
͍͍ͩͨ͜Μͳײ͡ func map<U>(f:T -> U) -> ͋Δ<U> Optional func map<U>(@noescape
f: (Wrapped) throws -> U) rethrows -> U? • Wrapped->UͷؔΛWrappedʹద༻ͯ͠U?Λฦ͢ • ͋Δ<U>͜͜ͰU?
͍͍ͩͨ͜Μͳײ͡ func map<U>(f:T -> U) -> ͋Δ<U> Array func map<T>(@noescape
transform: (Self.Generator.Element) throws -> T) rethrows -> [T] • Self.Generator.Element->TͷؔΛ Self.Generator.Elementʹద༻ͯ͠[T]Λฦ͢ • ͋Δ<U>͜͜Ͱ[U]
͍͍ͩͨ͜Μͳײ͡ func map<U>(f:T -> U) -> ͋Δ<U> ObservableType public func
map<R>(selector: Self.E throws -> R) -> RxSwift.Observable<R> • Self.E->RͷؔΛSelf.Eʹద༻ͯ͠ RxSwift.Observable<R>Λฦ͢ • ͋Δ<U>͜͜ͰRxSwift.Observable<R>
Μʁ
Ͳͷmapಉ͡ʢ͖ͬ͞ݴͬͨʣ func map<U>(f:T -> U) -> ͋Δ<U> • ͋Δ<T>ʹؔ(T->U)Λద༻ͯ͋͠Δ<U>Λฦ͢
۩ମతʹ func map<String>(f:Int -> String) -> Optional<String> Optional let o:Optional<String>
= Optional<Int>(1).map{String($0)}
۩ମతʹ func map<String>(f:Int -> String) -> Array<String> Array let a:Array<String>
= Array(arrayLiteral: 1,2,3).map {String($0)}
۩ମతʹ func map<String>(f:Int -> String) -> Observable<String> ObservableType let o:Observable<String>
= Observable.just(1).map{String($0)}
ΈΜͳಉͩ͡Ͷʢ͖ͬ͞ݴͬͨʣ let a:͋Δ<U> = ͋Δ<T>.map{U($0)} • ͋Δ͕ • Optional •
Array • Observable ʹͳΔΘ͚Ͱ͢ͳ
͋ΔͬͯԿʁ
Functor • શମΛҠͤΔͷΛද͢ • ؔखͱ͍͏Β͍͠ • ശʹྫ͑ΒΕΔࣄ͕͋Δ Πϝʔδ let a:Functor<U>
= Functor<T>.map{U($0)}
Functor let o:Optional<String> = Optional<Int>(1).map{String($0)} map͕͍ͯ͠Δ͜ͱ 1. Optional<Int>ͱ͍͏ശͷதΛऔΓग़͠ɺ͜ΕΛ$0ͱ͢ Δɻ 2.
$0ΛStringʹΩϟετ 3. $0ΛOptional<String>ͱ͍͏ശʹೖΕͯฦ͢
Functor let a:Array<String> = Array(arrayLiteral: 1,2,3).map {String($0)} map͕͍ͯ͠Δ͜ͱ 1. Array<Int>ͱ͍͏ശͷதΛऔΓग़͠ɺ͜ΕΛ$0ͱ͢Δɻ
2. $0ʢ֤ཁૉʣΛStringʹΩϟετ 3. $0ΛArray<String>ͱ͍͏ശʹೖΕͯฦ͢
Functor let o:Observable<String> = Observable.just(1).map{String($0)} map͕͍ͯ͠Δ͜ͱ 1. Observable<Int>ͱ͍͏ശͷதΛऔΓग़͠ɺ͜ΕΛ$0ͱ͢ Δɻ 2.
$0ΛStringʹΩϟετ 3. $0ΛObservable<String>ͱ͍͏ശʹೖΕͯฦ͢
·ͱΊ • mapͷഎޙʹFunctorͱ͍͏֓೦͕͋Δ • FunctorશମΛҠͤΔΛ͋ΒΘ͢ • ࠓճͷྫͰOptional,Array,Observable • શମΛҠ͢ಈ࡞͕mapͰ͋Δ