Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Updated example
Browse files Browse the repository at this point in the history
  • Loading branch information
srfrog committed Nov 9, 2020
1 parent 55d8e6f commit 1f51dcd
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@

Install using "go get":

go get github.com/srfrog/slices
```bash
go get github.com/srfrog/slices
```

Then import from your source:

import "github.com/srfrog/slices"
```
import "github.com/srfrog/slices"
```

View [example_test.go][1] for an extended example of basic usage and features.
View [example_test.go][1] for examples of basic usage and features.

## Documentation

Expand All @@ -45,41 +49,30 @@ import(
)

func main() {
ss := []string{"Go", "nuts", "for", "Go"}

foo := slices.Repeat("Go",3)
fmt.Println(foo)

fmt.Println(slices.Count(ss, "Go"))

fmt.Println(slices.Index(ss, "Go"))
fmt.Println(slices.LastIndex(ss, "Go"))

if slices.Contains(ss, "nuts") {
ss = slices.Replace(ss, []string{"Insanely"})
}
fmt.Println(ss)

str := slices.Shift(&ss)
fmt.Println(str)
fmt.Println(ss)
str := `Don't communicate by sharing memory - share memory by communicating`

slices.Unshift(&ss, "Really")
fmt.Println(ss)
// Split string by spaces into a slice.
slc := strings.Split(str, " ")

fmt.Println(slices.ToUpper(ss))
fmt.Println(slices.ToLower(ss))
fmt.Println(slices.ToTitle(ss))
// Count the number of "memory" strings in slc.
memories := slices.Count(slc, "memory")
fmt.Println("Memories:", memories)

fmt.Println(slices.Trim(ss,"Really"))
fmt.Println(slices.Filter(ss,"Go"))
// Split slice into two parts.
parts := slices.Split(slc, "-")
fmt.Println("Split:", parts, len(parts))

fmt.Println(slices.Diff(ss,foo))
fmt.Println(slices.Intersect(ss,foo))
// Compare second parts slice with original slc.
diff := slices.Diff(slc, parts[1])
fmt.Println("Diff:", diff)

fmt.Println(slices.Rand(ss,2))
// Chunk the slice
chunks := slices.Chunk(parts[0], 1)
fmt.Println("Chunk:", chunks)

fmt.Println(slices.Reverse(ss))
// Merge the parts
merge := slices.Merge(chunks...)
fmt.Println("Merge:", merge)
}
```

Expand Down

0 comments on commit 1f51dcd

Please sign in to comment.