Skip to content

isacikgoz/slices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

build goversion Go Reference coverage

Slices

slices package provides some utility functions on Go slice types. It leverages the generic types hence requires Go 1.18 and above.

Download

You can simply run go get github.com/isacikgoz/slices to start using in your own code.

Examples

Delete with preserving the order of the slice

s := []int{0, 1, 2, 3}
s = slices.Delete(s, 0) // removes the first element from the slice

Insert another slice from an index

s1 := []int{0, 3, 4, 5}
s2 := []int{1, 2}
s1 = slices.Insert(s1, 1, s2...) // will have (0, 1, 2, 3, 4, 5)

Filter slice

s1 := []string{
    "http://foo.com",
    "https://bar.com",
    "https://example.net",
    "http://go.org",
}

s2 := Filter(s1, func(v string) bool {
    return strings.HasPrefix(v, "https://")
})

// s2 will be {"https://bar.com", "https://example.net"}

License

BSD-3-Clause

About

Utility functions for Go slice types.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages