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: Tuples and Functions
Search
Antonio Bello
November 16, 2014
Programming
0
68
Swift: Tuples and Functions
SwiftCrunch, Krakow, Nov 16, 2014
Antonio Bello
November 16, 2014
Tweet
Share
More Decks by Antonio Bello
See All by Antonio Bello
Slices of Swift
jeden
1
59
From Learning to Mastering
jeden
4
150
Other Decks in Programming
See All in Programming
QA x AIエコシステム段階構築作戦
osu
0
250
Reactの歴史を振り返る
tutinoko
1
170
バイブコーディングの正体——AIエージェントはソフトウェア開発を変えるか?
stakaya
5
810
decksh - a little language for decks
ajstarks
4
21k
Claude Code で Astro blog を Pages から Workers へ移行してみた
codehex
0
180
プロダクトという一杯を作る - プロダクトチームが味の責任を持つまでの煮込み奮闘記
hiliteeternal
0
440
Constant integer division faster than compiler-generated code
herumi
2
550
変化を楽しむエンジニアリング ~ いままでとこれから ~
murajun1978
0
690
Strands Agents で実現する名刺解析アーキテクチャ
omiya0555
1
110
あのころの iPod を どうにか再生させたい
orumin
2
2.3k
AIに安心して任せるためにTypeScriptで一意な型を作ろう
arfes0e2b3c
0
340
リッチエディターを安全に開発・運用するために
unachang113
1
360
Featured
See All Featured
A designer walks into a library…
pauljervisheath
207
24k
[RailsConf 2023] Rails as a piece of cake
palkan
56
5.7k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
How to train your dragon (web standard)
notwaldorf
96
6.2k
Become a Pro
speakerdeck
PRO
29
5.5k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.8k
Adopting Sorbet at Scale
ufuk
77
9.5k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
47
9.6k
Into the Great Unknown - MozCon
thekraken
40
2k
The Cost Of JavaScript in 2023
addyosmani
51
8.8k
Transcript
Swi$ Tuples'and'Func-ons Antonio&Bello Freelancer Code%Ar(st,%Polyglot%Developer @ant_bello
What's'a'tuple? A"tuple"it's"an"anonymous"struct • it$can$contain$mul,ple$heterogeneous$values • values$can$be$named$or$anonymous
Return'mul*ple'values func quotientAndRemainder(# dividend: Int, # divisor: Int) -> (quotient:
Int, remainder: Int) { let quotient = dividend / divisor return (quotient: quotient, remainder: dividend - divisor * quotient) } let result = quotientAndRemainder( dividend: 59, divisor: 13)
Pass$parameters$to$func/ons$and$ methods func quotientAndRemainder(# dividend: Int, # divisor: Int) ->
(quotient: Int, remainder: Int) { let quotient = dividend / divisor return (quotient: quotient, remainder: dividend - divisor * quotient) } let params = (dividend: 61, divisor: 7) let result = quotientAndRemainder(params)
Func%on'arguments'and'return' values'are'tuples A"func'on"with"no"parameters"takes"an"empty"tuple" ():" func doNothing() {...}
Func%on'arguments'and'return' values'are'tuples A"func'on"returning"Void"actually"returns"an"empty" tuple"(): func doSomething() -> () {...}
Func%on'arguments'and'return' values'are'tuples A"func'on"expec'ng"one"parameter"and"returning"a" single"value"actually: • takes'a'tuple'with'one'value • returns'a'tuple'with'one'value func doSomething(value:
Int) -> (Int) { ... }
Use$Cases
Use$cases Collec&ng)parameters)before) func&on)call Without'tuples ... var dividend = 29 ...
var divisor = 3 ... let result = quotientAndRemainder( dividend: dividend, divisor: divisor)
Use$cases Collec&ng)parameters)before) func&on)call With%tuples var params: (dividend: Int, divisor: Int)
... params.dividend = 29 ... params.divisor = 3 ... let immutableParams = params let result = quotientAndRemainder(immutable)
Important! A"tuple"passed"to"a"func/on"must"be"immutable let immutableParams = params let result = quotientAndRemainder(immutableParams)
Use$cases Buffering)func,on)calls Some%Code...
Thank&You code%@%github/jeden Antonio&Bello @ant_bello