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
360
Material designのWindow size classについて
oyuk
0
1k
Swiftでなんで[weak self]するのか?
oyuk
2
4.7k
LLVMについて調べた
oyuk
0
170
Other Decks in Programming
See All in Programming
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
400
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
140
命名をリントする
chiroruxx
1
420
PHPUnitしか使ってこなかった 一般PHPerがPestに乗り換えた実録
mashirou1234
0
230
Security_for_introducing_eBPF
kentatada
0
110
return文におけるstd::moveについて
onihusube
1
1.2k
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
6
1.4k
わたしの星のままで一番星になる ~ 出産を機にSIerからEC事業会社に転職した話 ~
kimura_m_29
0
180
useSyncExternalStoreを使いまくる
ssssota
6
1.2k
テストケースの名前はどうつけるべきか?
orgachem
PRO
0
140
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
510
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
49
11k
BBQ
matthewcrist
85
9.4k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Facilitating Awesome Meetings
lara
50
6.1k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
520
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
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Ͱ͋Δ