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
340
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
Vue3の一歩踏み込んだパフォーマンスチューニング2024
hal_spidernight
3
3.1k
OpenTelemetryでRailsのパフォーマンス分析を始めてみよう(KoR2024)
ymtdzzz
4
1.6k
gopls を改造したら開発生産性が高まった
satorunooshie
8
240
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
9
1k
Vue.js学習の振り返り
hiro_xre
2
130
VR HMDとしてのVision Pro+ゲーム開発について
yasei_no_otoko
0
110
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
レガシーな Android アプリのリアーキテクチャ戦略
oidy
1
170
推し活の ハイトラフィックに立ち向かう Railsとアーキテクチャ - Kaigi on Rails 2024
falcon8823
6
2.3k
Piniaの現状と今後
waka292
5
1.5k
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
210
Hotwire or React? ~Reactの録画機能をHotwireに置き換えて得られた知見~ / hotwire_or_react
harunatsujita
9
4.1k
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.6k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
Testing 201, or: Great Expectations
jmmastey
38
7k
Navigating Team Friction
lara
183
14k
Into the Great Unknown - MozCon
thekraken
31
1.5k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Learning to Love Humans: Emotional Interface Design
aarron
272
40k
Faster Mobile Websites
deanohume
304
30k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
32
1.8k
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Ͱ͋Δ