mirror of
https://github.com/jbranchaud/til
synced 2026-01-20 15:38:02 +00:00
Compare commits
4 Commits
f5cb20767b
...
5b07d46c89
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b07d46c89 | ||
|
|
bf6a10e2cd | ||
|
|
5615da920f | ||
|
|
c60c63f554 |
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1529 TILs and counting..._
|
_1530 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ _1529 TILs and counting..._
|
|||||||
- [Aliasing An Ansible Host](devops/aliasing-an-ansible-host.md)
|
- [Aliasing An Ansible Host](devops/aliasing-an-ansible-host.md)
|
||||||
- [Allow Cross-Origin Requests To Include Cookies](devops/allow-cross-origin-requests-to-include-cookies.md)
|
- [Allow Cross-Origin Requests To Include Cookies](devops/allow-cross-origin-requests-to-include-cookies.md)
|
||||||
- [Allow HTTPS Through Your UFW Firewall](devops/allow-https-through-your-ufw-firewall.md)
|
- [Allow HTTPS Through Your UFW Firewall](devops/allow-https-through-your-ufw-firewall.md)
|
||||||
- [Check For Cached Site Assocation File For iOS](devops/check-for-cached-site-association-file-for-ios.md)
|
- [Check For Cached Site Association File For iOS](devops/check-for-cached-site-association-file-for-ios.md)
|
||||||
- [Check The Status of All Services](devops/check-the-status-of-all-services.md)
|
- [Check The Status of All Services](devops/check-the-status-of-all-services.md)
|
||||||
- [Check The Syntax Of nginx Files](devops/check-the-syntax-of-nginx-files.md)
|
- [Check The Syntax Of nginx Files](devops/check-the-syntax-of-nginx-files.md)
|
||||||
- [Connect To An RDS PostgreSQL Database](devops/connect-to-an-rds-postgresql-database.md)
|
- [Connect To An RDS PostgreSQL Database](devops/connect-to-an-rds-postgresql-database.md)
|
||||||
@@ -399,6 +399,7 @@ _1529 TILs and counting..._
|
|||||||
|
|
||||||
- [Access Go Docs Offline](go/access-go-docs-offline.md)
|
- [Access Go Docs Offline](go/access-go-docs-offline.md)
|
||||||
- [Build For A Specific OS And Architecture](go/build-for-a-specific-os-and-architecture.md)
|
- [Build For A Specific OS And Architecture](go/build-for-a-specific-os-and-architecture.md)
|
||||||
|
- [Combine Two Slices](go/combine-two-slices.md)
|
||||||
- [Do Something N Times](go/do-something-n-times.md)
|
- [Do Something N Times](go/do-something-n-times.md)
|
||||||
- [Find Executables Installed By Go](go/find-executables-installed-by-go.md)
|
- [Find Executables Installed By Go](go/find-executables-installed-by-go.md)
|
||||||
- [Not So Random](go/not-so-random.md)
|
- [Not So Random](go/not-so-random.md)
|
||||||
@@ -735,7 +736,7 @@ _1529 TILs and counting..._
|
|||||||
- [Check If Clusters Are Upgrade Compatible](postgres/check-if-clusters-are-upgrade-compatible.md)
|
- [Check If Clusters Are Upgrade Compatible](postgres/check-if-clusters-are-upgrade-compatible.md)
|
||||||
- [Check If The Local Server Is Running](postgres/check-if-the-local-server-is-running.md)
|
- [Check If The Local Server Is Running](postgres/check-if-the-local-server-is-running.md)
|
||||||
- [Check If User Role Exists For Database](postgres/check-if-user-role-exists-for-database.md)
|
- [Check If User Role Exists For Database](postgres/check-if-user-role-exists-for-database.md)
|
||||||
- [Check Table For Any Oprhaned Records](postgres/check-table-for-any-orphaned-records.md)
|
- [Check Table For Any Orphaned Records](postgres/check-table-for-any-orphaned-records.md)
|
||||||
- [Checking Inequality](postgres/checking-inequality.md)
|
- [Checking Inequality](postgres/checking-inequality.md)
|
||||||
- [Checking The Type Of A Value](postgres/checking-the-type-of-a-value.md)
|
- [Checking The Type Of A Value](postgres/checking-the-type-of-a-value.md)
|
||||||
- [Clear The Screen In psql](postgres/clear-the-screen-in-psql.md)
|
- [Clear The Screen In psql](postgres/clear-the-screen-in-psql.md)
|
||||||
|
|||||||
51
go/combine-two-slices.md
Normal file
51
go/combine-two-slices.md
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
# Combine Two Slices
|
||||||
|
|
||||||
|
The `append` function can be used to create a new slice with the contents of
|
||||||
|
the given slice and one or more items added to the end.
|
||||||
|
|
||||||
|
We can add one or more items like so:
|
||||||
|
|
||||||
|
```go
|
||||||
|
s1 := []int{1, 2, 3, 4}
|
||||||
|
s2 := append(s1, 5)
|
||||||
|
s3 := append(s2, 6, 7, 8)
|
||||||
|
|
||||||
|
fmt.Println(s1) //=> [1 2 3 4]
|
||||||
|
fmt.Println(s2) //=> [1 2 3 4 5]
|
||||||
|
fmt.Println(s3) //=> [1 2 3 4 5 6 7 8]
|
||||||
|
```
|
||||||
|
|
||||||
|
But what if we have a second slice instead of individual items? We could import
|
||||||
|
`slices` and use its `Concat` function. Or we can stick with `append` and
|
||||||
|
unpack that slice as a series of arguments into the second part of `append`
|
||||||
|
using `slice...`.
|
||||||
|
|
||||||
|
```go
|
||||||
|
s4 := append(s2, s1...)
|
||||||
|
fmt.Println(s4) //=> [1 2 3 4 5 1 2 3 4]
|
||||||
|
```
|
||||||
|
|
||||||
|
Here is the full example:
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
s1 := []int{1, 2, 3, 4}
|
||||||
|
s2 := append(s1, 5)
|
||||||
|
s3 := append(s2, 6, 7, 8)
|
||||||
|
|
||||||
|
fmt.Println(s1)
|
||||||
|
fmt.Println(s2)
|
||||||
|
fmt.Println(s3)
|
||||||
|
|
||||||
|
s4 := append(s2, s1...)
|
||||||
|
fmt.Println(s4)
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
[source](https://pkg.go.dev/builtin#append)
|
||||||
Reference in New Issue
Block a user