Functions that operate on slices. Similar to functions from package strings
or package bytes
that have been adapted to work with slices.
- Using a thin layer of idiomatic Go; correctness over performance.
- Provide most basic slice operations: index, trim, filter, map
- Some PHP favorites like: pop, push, shift, unshift, shuffle, etc...
- Non-destructive returns (won't alter original slice), except for explicit tasks.
Install using "go get":
go get github.com/srfrog/slices
Then import from your source:
import "github.com/srfrog/slices"
View example_test.go for an extended example of basic usage and features.
The full code documentation is located at GoDoc:
http://godoc.org/github.com/srfrog/slices
This is a en example showing basic usage.
package main
import(
"fmt"
"github.com/srfrog/slices"
)
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)
slices.Unshift(&ss, "Really")
fmt.Println(ss)
fmt.Println(slices.ToUpper(ss))
fmt.Println(slices.ToLower(ss))
fmt.Println(slices.ToTitle(ss))
fmt.Println(slices.Trim(ss,"Really"))
fmt.Println(slices.Filter(ss,"Go"))
fmt.Println(slices.Diff(ss,foo))
fmt.Println(slices.Intersect(ss,foo))
fmt.Println(slices.Rand(ss,2))
fmt.Println(slices.Reverse(ss))
}