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
100
Go and Node.js: a comparison
nathany
1
200
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
98
Go Types
nathany
2
130
Go Packages
nathany
2
540
Other Decks in Programming
See All in Programming
Model Pollution
hschwentner
1
160
RailsGirls IZUMO スポンサーLT
16bitidol
0
200
Rails Frontend Evolution: It Was a Setup All Along
skryukov
0
280
CDK引数設計道場100本ノック
badmintoncryer
2
480
코딩 에이전트 체크리스트: Claude Code ver.
nacyot
0
930
はじめてのWeb API体験 ー 飲食店検索アプリを作ろうー
akinko_0915
0
140
Flutterで備える!Accessibility Nutrition Labels完全ガイド
yuukiw00w
0
170
GPUを計算資源として使おう!
primenumber
1
250
PipeCDのプラグイン化で目指すところ
warashi
1
300
バイブコーディング超えてバイブデプロイ〜CloudflareMCPで実現する、未来のアプリケーションデリバリー〜
azukiazusa1
0
330
状態遷移図を書こう / Sequence Chart vs State Diagram
orgachem
PRO
2
200
ご注文の差分はこちらですか? 〜 AWS CDK のいろいろな差分検出と安全なデプロイ
konokenj
3
580
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
How to Ace a Technical Interview
jacobian
278
23k
Embracing the Ebb and Flow
colly
86
4.8k
Building Flexible Design Systems
yeseniaperezcruz
328
39k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.8k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
750
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
Faster Mobile Websites
deanohume
308
31k
Six Lessons from altMBA
skipperchong
28
3.9k
Practical Orchestrator
shlominoach
189
11k
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