Categorygithub.com/go-corelibs/slices
modulepackage
1.6.2
Repository: https://github.com/go-corelibs/slices.git
Documentation: pkg.go.dev

# README

godoc codecov Go Report Card

slices - go slice type utilities

slices is a package doing all sorts of things with slices of stuff.

Installation

> go get github.com/go-corelibs/slices@latest

Examples

Cut

func main() {
    slice := []string{"Before", "things", "|", "After", "things"}
    before, after, found := Cut(slice, []string{"|"})
    // found == true
    // before == []string{"Before", "things"}
    // after == []string{"After", "things"}
}

Carve, CarveString

func main() {
    // slices.Carve is a generic list carving function which is most easily
    // demonstrated with a slice of runes yet useful for any comparable slice
    slice := []rune(`This is STARTa sliceEND of runes`)
    before, middle, after, found := Carve(slice, []rune("START"), []rune("END"))
    // found == true
    // before == []rune("This is ")
    // middle == []rune("a slice")
    // after == []rune(" of runes")

    // slices.CarveString is a convenient wrapper around slices.Carve geared
    // for use with ~string types, making the above slices.Carve example look
    // like this:
    s := `This is STARTa a stringEND of characters`
    b, m, a, ok := CarveString(s, "START", "END")
    // ok == true
    // before == "This is "
    // middle == "a string"
    // after == " of characters"
}

Go-CoreLibs

Go-CoreLibs is a repository of shared code between the Go-Curses and Go-Enjin projects.

License

Copyright 2023 The Go-CoreLibs Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use file except in compliance with the License.
You may obtain a copy of the license at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

# Functions

AnyWithin returns true if any of the values in the source given are present in any of the other slices given.
Append returns a new slice appended with only values not within the src slice.
Carve finds the `start` and `end` markers in `src` and carves out the "before carve", "middle of start/end range" and "after carve" segments.
CarveString recasts the given ~string arguments to []rune slices, calls Carve and recasts the []rune slices returns values back to the original type.
Copy creates a new slice (array) from the given slice.
Cut is the slices version of strings.Cut.
DuplicateCounts returns a mapping of values and their respective counts, distinct values not included.
Equal returns true if all the slices given have the same values.
IndexesOf returns a list of all indexes matching the value given.
IndexOf returns the first index matching the value given.
Insert creates a new slice (array) from the given slice, with additional values inserted at the given index.
MakeLookup creates a mapping of generic comparable slices with empty structs.
Merge returns a new slice with the new values found within others appended to the src slice.
NewStack creates a new Stack instance.
NewStackComparable creates a new StackComparable instance.
NewStackUnique creates a new StackUnique instance.
Pop removes the last value from a Copy of the slice and returns it.
Present returns true if the search value is present in any of the other values given.
Prune removes all instances of the specified values from a copy of the given slice.
Push appends the given value to a new copy of the given slice.
Remove creates a new slice (array) from the given slice, with the specified index removed.
No description provided by the author
Shift prepends the given value to a new copy of the given slice.
StartsWith returns true if the other slices given start with the same values as the src.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ToStrings creates a new string slice with all the given slice's values, converted to strings using fmt.Sprintf("%v", value) unless the value is of type rune, string, []byte or []rune, in which case they're simply recast as string.
Truncate creates a new slice (array), of specified length, from the given slice.
Unique returns a new slice with duplicate values omitted, maintaining order.
Unshift removes the first value from a Copy of the slice and returns it.
Within return true if the search value is present in any of the other slices of V given.

# Structs

Stack is a concurrency-safe manager for a stack of generic items.
StackComparable is a concurrency-safe manager for a stack of generic comparable items.
StackUnique is a concurrency-safe manager for a stack of unique generic comparable items.