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
Go Arrays & Slices
Search
Nathan Youngman
May 25, 2015
Programming
0
140
Go Arrays & Slices
An overview of how slices and arrays work in Go.
Nathan Youngman
May 25, 2015
Tweet
Share
More Decks by Nathan Youngman
See All by Nathan Youngman
The Healthy Programmer
nathany
2
98
Go and Node.js: a comparison
nathany
1
190
Diet Hacks
nathany
2
360
Go 1.6 and HTTP/2
nathany
3
130
Upgrading Rails Redux
nathany
1
88
GopherCon recap
nathany
0
170
Go Functions
nathany
0
96
Go Types
nathany
2
130
Go Packages
nathany
2
540
Other Decks in Programming
See All in Programming
TSConfig Solution Style & subpath imports to switch types on a per-file basis
maminami373
1
180
マテリアルって何者?RealityKitで扱うマテリアル入門
nao_randd
0
140
コードに語らせよう――自己ドキュメント化が内包する楽しさについて / Let the Code Speak
nrslib
5
920
鯛変だったRubyKaigi 2025 ── それでも楽しかった!
pndcat
0
130
OpenTelemetryで始めるベンダーフリーなobservability / Vendor-free observability starting with OpenTelemetry
seike460
PRO
0
160
バリデーションライブラリ徹底比較
nayuta999999
1
410
"使いづらい" をリバースエンジニアリングする UI の読み解き方
rebase_engineering
0
110
メモリリークが発生した時にpprofを使用して原因特定した話
zono33lhd
0
100
型付け力を強化するための Hoogle のすゝめ / Boosting Your Type Mastery with Hoogle
guvalif
1
230
漸進。
ssssota
0
990
rbs-traceを使ってWEARで型生成を試してみた After RubyKaigi 2025〜ZOZO、ファインディ、ピクシブ〜 / tried rbs-trace on WEAR
oyamakei
0
1k
Proxmoxをまとめて管理できるコンソール作ってみました
karugamo
1
400
Featured
See All Featured
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
750
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
5
620
Rails Girls Zürich Keynote
gr2m
94
13k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
228
22k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.3k
Become a Pro
speakerdeck
PRO
28
5.4k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Building an army of robots
kneath
306
45k
Mobile First: as difficult as doing things right
swwweet
223
9.6k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Transcript
gophers := [4]string{"blue", "pink", "purple", "blue"}
Arrays are fixed-length planets := [8]string{ "Mercury", "Venus", "Earth", "Mars",
"Jupiter", "Saturn", "Uranus", "Neptune", } 0 1 2 3 4 5 6 7
Arrays are values planetBackup := planets // make way
for an interstellar bypass planets[2] = “" fmt.Println(planets) // [Mercury Venus Mars Jupiter Saturn Uranus Neptune] fmt.Println(planetBackup) // [Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune]
Slicing makes a window terrestrial := planets[0:4] gasGiants := planets[4:6]
iceGiants := planets[6:8] 0 1 2 3 4 5 6 7 terrestrial gasGiants iceGiants
Half-open range planets[2:3] // [Earth] < 3 • starts at
index 2 • excludes index 3
Defaults terrestrial := planets[:4] gasGiants := planets[4:6] iceGiants := planets[6:]
allPlanets := planets[:]
Making a slice // allPlanets := planets[:] planets := []string{
"Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", }
Append to slices planets = append(planets, "Pluto") 0 1 2
3 4 5 6 7 8 9 10 11 12 13 14 15 fmt.Println(len(planets), cap(planets)) // 9 16
Append again planets = append(planets, "Eris", "Sedna") fmt.Println(len(planets), cap(planets))
// 11 16
http://blog.golang.org/go-slices-usage-and-internals https://github.com/golang/go/wiki/SliceTricks More reading