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
関数を引数として渡す書き方のポイント
Search
Yoshikuni Kato
September 17, 2017
Programming
0
760
関数を引数として渡す書き方のポイント
iOSDC LT
https://iosdc.jp/2017/node/1454
Yoshikuni Kato
September 17, 2017
Tweet
Share
More Decks by Yoshikuni Kato
See All by Yoshikuni Kato
The Elm Architecture & Swift
yoching
0
890
iOS developers community in Tokyo
yoching
0
640
Swiftエンジニアが海外のポジションに応募する
yoching
10
2.9k
App Architecture By Manual DI
yoching
0
650
Passing function to function arguments
yoching
0
620
「新規アプリの設計」を設計する
yoching
1
1.8k
App Architecture By Manual DI
yoching
2
530
App Architecture Sample
yoching
0
92
San Francisco Report
yoching
0
650
Other Decks in Programming
See All in Programming
「Chatwork」Android版アプリを 支える単体テストの現在
okuzawats
0
180
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
160
Stackless и stackful? Корутины и асинхронность в Go
lamodatech
0
690
42 best practices for Symfony, a decade later
tucksaun
1
180
The rollercoaster of releasing an Android, iOS, and macOS app with Kotlin Multiplatform | droidcon Italy
prof18
0
150
ブラウザ単体でmp4書き出すまで - muddy-web - 2024-12
yue4u
2
460
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
180
Fibonacci Function Gallery - Part 1
philipschwarz
PRO
0
210
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
return文におけるstd::moveについて
onihusube
1
920
Featured
See All Featured
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Thoughts on Productivity
jonyablonski
67
4.4k
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Designing for Performance
lara
604
68k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Unsuck your backbone
ammeep
669
57k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Transcript
ؔΛҾͱͯ͢͠ॻ͖ํͷϙΠϯτ Ճ౻༝܇ / @yoshikuni_kato iOSDC 2017 2017/09/17 1
Who am I? • Ճ౻༝܇ʢYoshikuni Katoʣ @yoshikuni_kato • iOSΤϯδχΞʢ2.5 yearsʣ
• Yahoo! Japan -> Φϋί • ʮϥδ͐ʯ͘Μ → • Interests: ઃܭ / FRP / Coordinator PaFern / UI࣮ 2
func%onalʹॻ͘ • func&onalʹॻ͘͜ͱ͕૿͖͑ͯͨ • FRP (RxSwi3 / Reac&veSwi3) • map
/ filter / reduce • iffor͕ݮΔ • એݴతʹॻ͚Δ 3
͜ͷLTͰγΣΞ͢Δ͜ͱ • ؔΛҾͱͯ͢͠߹ͷॻ͖ํ → গ͠ͷมߋ͚ͩͲɺΑΓએݴతʹݟ͑Δํ๏ • arrayͷmapΛྫʹ 4
ॻ͖ํ̍ - ΫϩʔδϟΛॻ͘ let array: [Int] = [1, 2, 3]
array.map { number -> Int in return number * 2 } 5
arrayͷmapͷఆٛ func map<T>(_ transform: (Element) throws -> T) rethrows ->
[T] • mapͷҾɿElementΛड͚औͬͯTΛฦ͢Ϋϩʔδϟ • ؔɺ໊લ͖ͷΫϩʔδϟͱଊ͑ΒΕΔ • ؔࣗମΛ͢͜ͱ͕Ͱ͖Δ 6
ॻ͖ํ̎ - ؔΛ͢ // ઌʹؔΛఆٛ func twoTimes(of number: Int) ->
Int { return number * 2 } let array: [Int] = [1, 2, 3] array.map(twoTimes) // ؔΛ͢ 7
ύϥϝʔλʔ͕ෳ͋Δ߹ func someFunc(a: Int, b: Int) -> String { return
"a = \(a), b = \(b)" } let array: [Int] = [1, 2, 3] array .map { number -> (a: Int, b: Int) in return (a: number, b: number) // Ұ୴λϓϧʹ͢Δ } .map(someFunc) 8
ΠχγϟϥΠβͷ߹ struct Sample { let number: Int init(number: Int) {
self.number = number } } 9
ॻ͖ํ̍ - ΫϩʔδϟΛॻ͘ let array: [Int] = [1, 2, 3]
array.map { number -> Sample in return Sample(number: number) } 10
ॻ͖ํ̎ - ؔΛ͢ let array: [Int] = [1, 2, 3]
array.map(Sample.init) • ΠχγϟϥΠβ(.init) = ͦͷObjectΛฦؔ͢ 11
ҧ͍ 1 array.map { number -> Sample in return Sample(number:
number) } array.map(Sample.init) 12
ҧ͍ 2 array .map { number -> Int in return
number * 2 } .map { number -> Sample in return Sample(number: number) } .map { sample -> Foo in return Foo(sample: sample) } array .map(twoTimes) .map(Sample.init) .map(Foo.init) 13
·ͱΊ • গ͠ॻ͖ํΛม͑Δ͚ͩͰɺΑΓએݴతʹॻ͚Δํ๏Λհ • ׆༻ྫɿModel͔ΒViewModelͷม ɹ model.map(ViewModel.init) • ݁ՌతʹɺॲཧΛؔʹΓग़͍ͯ͘͜͠ͱʹͳΔ •
ؔΛ͍ͯ͘͠ײ֮ʢखଓ͖ܕͷײ͔֮ΒঃʑʹΕΔʣ 14
ࢀߟ • Connec'ng View Controllers, Swi3 Talk1 • From Run'me
Programming to Func'ons, Swi3 Talk2 2 h$ps:/ /talk.objc.io/episodes/S01E19-from-run@me-programming-to-func@ons 1 h$ps:/ /talk.objc.io/episodes/S01E05-connec;ng-view-controllers 15
͓·͚ func someFunc(a: Int, b: Int) -> String { return
"a: \(a), b: \(b)" } // λϓϧͤͳ͍ let parameters = (a: 0, b: 0) someFunc(parameters) // !ʢswift3~ʣ // mapͩͱͤΔ let array: [(Int, Int)] = [(0, 0)] array.map(someFunc) // "ʢswift3Ͱʣ • ͳͥॻ͚Δͷ͔͔͍ͬͯΔਓ͕͍ͨΒڭ͍͑ͯͩ͘͞ 16