Documentation ¶
Overview ¶
utils slice manupulation Ref. https://github.com/golang/go/wiki/SliceTricks TODO: function chaining as in : https://github.com/elliotchance/pie
utils slice manupulation Ref. https://github.com/golang/go/wiki/SliceTricks TODO: function chaining as in : https://github.com/elliotchance/pie
Index ¶
- func BatchInt(a []int, size int) ([][]int, error)
- func BatchStr(a []string, size int) ([][]string, error)
- func Contain(item interface{}, slice interface{}) bool
- func CopyInt(a []int) []int
- func CopyStr(a []string) []string
- func CutInt(a []int, start int, end int) ([]int, error)
- func CutStr(a []string, start int, end int) ([]string, error)
- func DeduplicateInt(a []int) []int
- func DeduplicateStr(a []string) []string
- func DeleteInt(a []int, i int) ([]int, error)
- func DeleteStr(a []string, i int) ([]string, error)
- func ExpandInt(a []int, start int, end int) ([]int, error)
- func ExpandStr(a []string, start int, end int) ([]string, error)
- func ExtendInt(a []int, size int) ([]int, error)
- func ExtendStr(a []string, size int) ([]string, error)
- func FilterInt(a []int, ffunc func(int) bool) []int
- func FilterIntNoAllocate(a []int, f func(int) bool) []int
- func FilterStr(a []string, ffunc func(string) bool) []string
- func FilterStrNoAllocate(a []string, f func(string) bool) []string
- func InsertInt(a []int, item int, i int) ([]int, error)
- func InsertStr(a []string, item string, i int) ([]string, error)
- func InsertVecInt(a []int, b []int, i int) ([]int, error)
- func InsertVecStr(a []string, b []string, i int) ([]string, error)
- func PopFrontInt(a []int) (int, []int)
- func PopFrontStr(a []string) (string, []string)
- func PopInt(a []int) (int, []int)
- func PopStr(a []string) (string, []string)
- func PushFrontInt(a []int, item int) []int
- func PushFrontStr(a []string, item string) []string
- func PushInt(a []int, item int) []int
- func PushStr(a []string, item string) []string
- func Reverse(s interface{}) (retVal interface{})
- func ReverseInt(a []int) []int
- func ReverseLRInt(a []int) []int
- func ReverseLRStr(a []string) []string
- func ReverseStr(a []string) []string
- func ShuffleInt(a []int) []int
- func ShuffleStr(a []string) []string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contain ¶
func Contain(item interface{}, slice interface{}) bool
Contain checks whether a element is in a slice (same type)
func CutInt ¶
CutInt removes a sub-slice from start(inclusive in removed slice) to end (exclusive in remve slice) from original slice
func CutStr ¶
CutStr removes a sub-slice from start(inclusive in removed slice) to end (exclusive in remve slice) from original slice
func DeduplicateInt ¶
DeduplicateInt de-duplicates a slice in place
func DeduplicateStr ¶
DeduplicateStr de-duplicates a slice in place
func ExpandInt ¶
ExpandInt expands capacity of slice from `start` (inclusive) to `end` exclusive point.
func ExpandStr ¶
ExpandStr expands capacity of slice from `start` (inclusive) to `end` exclusive point.
func FilterIntNoAllocate ¶
FilterStrNoAllocate filters a slice without allocating. This trick uses the fact that a slice shares the same backing array and capacity as the original, so the storage is reused for the filtered slice. Of course, the original contents are modified.
func FilterStrNoAllocate ¶
FilterStrNoAllocate filters a slice without allocating. This trick uses the fact that a slice shares the same backing array and capacity as the original, so the storage is reused for the filtered slice. Of course, the original contents are modified.
func InsertVecInt ¶
InsertVecInt inserts a slice (`b`) to origin slice (`a`) at specified index point
func InsertVecStr ¶
InsertVecStr inserts a slice (`b`) to origin slice (`a`) at specified index point
func PopFrontInt ¶
PopFrontInt pops the first item from the slice (shift)
func PopFrontStr ¶
PopFrontStr pops the first item from the slice (shift)
func PushFrontInt ¶
PushFrontInt pushes an item to the front of a slice (unshift)
func PushFrontStr ¶
PushFrontStr pushes an item to the front of a slice (unshift)
func Reverse ¶
func Reverse(s interface{}) (retVal interface{})
Reverse reverses any slice Source: https://stackoverflow.com/questions/28058278
func ReverseInt ¶
ReverseInt replaces the contents of a slice with the same elements but in reverse order
func ReverseLRInt ¶
ReverseLRInt does the same as ReverseInt except with 2 indices
func ReverseLRStr ¶
ReverseLRStr does the same as ReverseStr except with 2 indices
func ReverseStr ¶
ReverseStr replaces the contents of a slice with the same elements but in reverse order
func ShuffleInt ¶
ShuffleInt shuffles a slice using Fisher–Yates algorithm Since go1.10, this is available at math/rand.Shuffle (https://godoc.org/math/rand#Shuffle)
func ShuffleStr ¶
ShuffleStr shuffles a slice using Fisher–Yates algorithm Since go1.10, this is available at math/rand.Shuffle (https://godoc.org/math/rand#Shuffle)
Types ¶
This section is empty.