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
750
関数を引数として渡す書き方のポイント
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
870
iOS developers community in Tokyo
yoching
0
630
Swiftエンジニアが海外のポジションに応募する
yoching
10
2.9k
App Architecture By Manual DI
yoching
0
640
Passing function to function arguments
yoching
0
610
「新規アプリの設計」を設計する
yoching
1
1.8k
App Architecture By Manual DI
yoching
2
520
App Architecture Sample
yoching
0
92
San Francisco Report
yoching
0
640
Other Decks in Programming
See All in Programming
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
7
430
CPython 인터프리터 구조 파헤치기 - PyCon Korea 24
kennethanceyer
0
240
Tuning GraphQL on Rails
pyama86
2
1k
qmuntal/stateless のススメ
sgash708
0
120
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
150
JaSST 24 九州:ワークショップ(は除く)実践!マインドマップを活用したソフトウェアテスト+活用事例
satohiroyuki
0
260
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
390
カスタムしながら理解するGraphQL Connection
yanagii
1
1.2k
C#/.NETのこれまでのふりかえり
tomokusaba
1
160
現場で役立つモデリング 超入門
masuda220
PRO
12
2.9k
色々なIaCツールを実際に触って比較してみる
iriikeita
0
270
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
7
2.8k
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
79
8.6k
Build The Right Thing And Hit Your Dates
maggiecrowley
32
2.4k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Agile that works and the tools we love
rasmusluckow
327
21k
Code Review Best Practice
trishagee
64
17k
Teambox: Starting and Learning
jrom
132
8.7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Navigating Team Friction
lara
183
14k
Statistics for Hackers
jakevdp
796
220k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
1.9k
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