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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yoshikuni Kato
September 17, 2017
Programming
880
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
関数を引数として渡す書き方のポイント
iOSDC LT
https://iosdc.jp/2017/node/1454
Yoshikuni Kato
September 17, 2017
More Decks by Yoshikuni Kato
See All by Yoshikuni Kato
Fun of writing Unison
yoching
0
640
The Elm Architecture & Swift
yoching
0
1.3k
iOS developers community in Tokyo
yoching
0
930
Swiftエンジニアが海外のポジションに応募する
yoching
10
3.3k
App Architecture By Manual DI
yoching
0
900
Passing function to function arguments
yoching
0
930
「新規アプリの設計」を設計する
yoching
1
2.2k
App Architecture By Manual DI
yoching
2
630
App Architecture Sample
yoching
0
120
Other Decks in Programming
See All in Programming
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
330
The NotImplementedError Problem in Ruby
koic
1
710
LLM Plugin for Node-REDの利用方法と開発について
404background
0
170
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
2
1.2k
Inside Stream API
skrb
1
680
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
130
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
260
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
220
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.6k
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.3k
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
180
Webフレームワークの ベンチマークについて
yusukebe
0
160
Featured
See All Featured
Heart Work Chapter 1 - Part 1
lfama
PRO
7
36k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
250
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
330
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
71
40k
ラッコキーワード サービス紹介資料
rakko
1
3.6M
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
250
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
210
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
480
Six Lessons from altMBA
skipperchong
29
4.3k
Documentation Writing (for coders)
carmenintech
77
5.4k
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