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
Functional Swift
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Ulrik Flænø Damm
July 23, 2014
Programming
0
97
Functional Swift
Presented at NSCoder Night Copenhagen
Ulrik Flænø Damm
July 23, 2014
Tweet
Share
Other Decks in Programming
See All in Programming
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.5k
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
6k
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
180
AgentCoreとHuman in the Loop
har1101
5
230
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.8k
AWS re:Invent 2025参加 直前 Seattle-Tacoma Airport(SEA)におけるハードウェア紛失インシデントLT
tetutetu214
2
110
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
190
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
550
疑似コードによるプロンプト記述、どのくらい正確に実行される?
kokuyouwind
0
380
CSC307 Lecture 02
javiergs
PRO
1
770
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
200
Oxlintはいいぞ
yug1224
5
1.3k
Featured
See All Featured
Writing Fast Ruby
sferik
630
62k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
1
98
The SEO identity crisis: Don't let AI make you average
varn
0
64
Claude Code のすすめ
schroneko
67
210k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
96
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
WENDY [Excerpt]
tessaabrams
9
36k
Navigating Weather and Climate Data
rabernat
0
100
Music & Morning Musume
bryan
47
7.1k
Building the Perfect Custom Keyboard
takai
2
680
Transcript
Hi! I’m ULRIK @ULRIKDAMM
FUNCTIONAL Swift
FUNCTIONS AS FIRST Class citizens
Int -> Int func sqr(i : Int) -> Int {
return i * i } { i in i * i } ~
None
None
PROCEDURAL
1 2 ff 2e ad load value to a load
value to b > add a and b and store in c print value c
FUNCTIONAL
None
MAP & REDUCE
MAP
REDUCE
MAP & REDUCE 1 2 3 1 4 9 0
14 (((0 + 1) + 4) + 9) = 14 sqr sqr sqr + + + =
IN SWIFT
IN SWIFT func map<U>(transform: (T) -> U) -> [U] func
reduce<U>(initial: U, combine: (U, T) -> U) -> U
IN SWIFT values.map(transform) values.reduce(initial, transform)
IN SWIFT [1, 2, 3].map { value in value +
1 } [1, 2, 3].reduce(0) { result, value in result + value }
CLOSURE SYNTAX
CLOSURE SYNTAX let closure : (Int, Int) -> Int =
{ value1, value2 -> Int in return value1 + value2 } [1, 2, 3].reduce(0, closure)
CLOSURE SYNTAX [1, 2, 3].reduce(0, { value1, value2 -> Int
in return value1 + value2 })
CLOSURE SYNTAX [1, 2, 3].reduce(0, { value1, value2 -> Int
in return value1 + value2 })
CLOSURE SYNTAX [1, 2, 3].reduce(0) { value1, value2 -> Int
in return value1 + value2 }
CLOSURE SYNTAX [1, 2, 3].reduce(0) { value1, value2 -> Int
in return value1 + value2 }
CLOSURE SYNTAX [1, 2, 3].reduce(0) { value1, value2 in return
value1 + value2 }
CLOSURE SYNTAX [1, 2, 3].reduce(0) { value1, value2 in return
value1 + value2 }
CLOSURE SYNTAX [1, 2, 3].reduce(0) { value1, value2 in value1
+ value2 }
CLOSURE SYNTAX [1, 2, 3].reduce(0) { value1, value2 in value1
+ value2 } // most common
CLOSURE SYNTAX [1, 2, 3].reduce(0) { value1, value2 in value1
+ value2 }
CLOSURE SYNTAX [1, 2, 3].reduce(0) { $0 + $1 }
CLOSURE SYNTAX [1, 2, 3].reduce(0) { $0 + $1 }
// short form
CLOSURE SYNTAX [1, 2, 3].reduce(0, +)
EXAMPLES
AVERAGE let values = [5, 8, 17] // procedural var
sum = 0 for value in values { sum += value } let average = sum / values.count // functional values.reduce(0, +) / values.count
COUNT OCCURENCES func count_occurences(vals : [Int], of val : Int)
-> Int { return vals.reduce(0) { count, this in return count + (val == this ? 1 : 0) } }
CONTAINS func contains(vals : [Int], find val : Int) ->
Bool { return vals.reduce(false) { found, this in if found { return true } else { return val == this } } }
WORDBASE func createPositions(positions : (Int, Int)...) -> [Position] { return
positions.map { position in return Position(x: position.0, y: position.1) } } func wordFromTiles(tiles : [Position]) -> String { return tiles.reduce("") { string, position in return string + self.characterAtPosition(position) } }
TYPE INFERENCE let ns = [1, 2, 3] ns.reduce(0, +)
// 6 let ss = ["1", "2", "3"] ss.reduce("", +) // “123" let moves = [(0,1) => (0,2), (5, 7) => (7, 7)] moves.reduce(ChessBoard(), +)
FIN