util

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchInt

func BatchInt(a []int, size int) ([][]int, error)

BatchInt slits a slice to batches (slice of slices)

func BatchStr

func BatchStr(a []string, size int) ([][]string, error)

BatchStr slits a slice to batches (slice of slices)

func Contain

func Contain(item interface{}, slice interface{}) bool

Contain checks whether a element is in a slice (same type)

func CopyInt

func CopyInt(a []int) []int

CopyInt copy a string slice to another

func CopyStr

func CopyStr(a []string) []string

CopyStr copy a string slice to another

func CutInt

func CutInt(a []int, start int, end int) ([]int, error)

CutInt removes a sub-slice from start(inclusive in removed slice) to end (exclusive in remve slice) from original slice

func CutStr

func CutStr(a []string, start int, end int) ([]string, error)

CutStr removes a sub-slice from start(inclusive in removed slice) to end (exclusive in remve slice) from original slice

func DeduplicateInt

func DeduplicateInt(a []int) []int

DeduplicateInt de-duplicates a slice in place

func DeduplicateStr

func DeduplicateStr(a []string) []string

DeduplicateStr de-duplicates a slice in place

func DeleteInt

func DeleteInt(a []int, i int) ([]int, error)

DeleteInt deletes an string item at specified index and preserves order

func DeleteStr

func DeleteStr(a []string, i int) ([]string, error)

DeleteStr deletes an string item at specified index and preserves order

func ExpandInt

func ExpandInt(a []int, start int, end int) ([]int, error)

ExpandInt expands capacity of slice from `start` (inclusive) to `end` exclusive point.

func ExpandStr

func ExpandStr(a []string, start int, end int) ([]string, error)

ExpandStr expands capacity of slice from `start` (inclusive) to `end` exclusive point.

func ExtendInt

func ExtendInt(a []int, size int) ([]int, error)

ExtendInt extends slice capacity by adding a spcified size at then end of slice.

func ExtendStr

func ExtendStr(a []string, size int) ([]string, error)

ExtendStr extends slice capacity by adding a spcified size at then end of slice.

func FilterInt

func FilterInt(a []int, ffunc func(int) bool) []int

FilterInt filters in place a int slice

func FilterIntNoAllocate

func FilterIntNoAllocate(a []int, f func(int) bool) []int

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 FilterStr

func FilterStr(a []string, ffunc func(string) bool) []string

FilterStr filters in place a string slice

func FilterStrNoAllocate

func FilterStrNoAllocate(a []string, f func(string) bool) []string

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 InsertInt

func InsertInt(a []int, item int, i int) ([]int, error)

InsertInt inserts an int to slice of int at specified index i.

func InsertStr

func InsertStr(a []string, item string, i int) ([]string, error)

InsertStr inserts an string to slice of string at specified index i.

func InsertVecInt

func InsertVecInt(a []int, b []int, i int) ([]int, error)

InsertVecInt inserts a slice (`b`) to origin slice (`a`) at specified index point

func InsertVecStr

func InsertVecStr(a []string, b []string, i int) ([]string, error)

InsertVecStr inserts a slice (`b`) to origin slice (`a`) at specified index point

func PopFrontInt

func PopFrontInt(a []int) (int, []int)

PopFrontInt pops the first item from the slice (shift)

func PopFrontStr

func PopFrontStr(a []string) (string, []string)

PopFrontStr pops the first item from the slice (shift)

func PopInt

func PopInt(a []int) (int, []int)

PopInt pops last item out of a give slice

func PopStr

func PopStr(a []string) (string, []string)

PopStr pops last item out of a give slice

func PushFrontInt

func PushFrontInt(a []int, item int) []int

PushFrontInt pushes an item to the front of a slice (unshift)

func PushFrontStr

func PushFrontStr(a []string, item string) []string

PushFrontStr pushes an item to the front of a slice (unshift)

func PushInt

func PushInt(a []int, item int) []int

PushInt pushes an item to a slice at the end of it.

func PushStr

func PushStr(a []string, item string) []string

PushStr pushes an item to a slice at the end of it.

func Reverse

func Reverse(s interface{}) (retVal interface{})

Reverse reverses any slice Source: https://stackoverflow.com/questions/28058278

func ReverseInt

func ReverseInt(a []int) []int

ReverseInt replaces the contents of a slice with the same elements but in reverse order

func ReverseLRInt

func ReverseLRInt(a []int) []int

ReverseLRInt does the same as ReverseInt except with 2 indices

func ReverseLRStr

func ReverseLRStr(a []string) []string

ReverseLRStr does the same as ReverseStr except with 2 indices

func ReverseStr

func ReverseStr(a []string) []string

ReverseStr replaces the contents of a slice with the same elements but in reverse order

func ShuffleInt

func ShuffleInt(a []int) []int

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

func ShuffleStr(a []string) []string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL