helpers

package
v0.0.0-...-9cd4eef Latest Latest
Warning

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

Go to latest
Published: May 7, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(arr []interface{}, value interface{}) bool

Contains checks if given value contains in the array

func ConvertSizeToString

func ConvertSizeToString(size int) string

ConvertSizeToString will convert a number of bytes into a KB, MG, and GB string format respectively given the number of bytes.

func ConvertToFloat

func ConvertToFloat(val interface{}) (*float64, bool)

ConvertToFloat will convert the given empty interface value to float64. Will consider int types also. If there's an error, will return a boolean confirming the result.

func Difference

func Difference(a, b []interface{}) []interface{}

Difference returns the set difference of two slices with any given values.

Only use acceptable key types for a Go map

func Filter

func Filter(arr []interface{}, test Predicate) ([]interface{}, error)

Filter method creates an returns a new slice with all elements that pass the test implemented by the provided function.

If an error is encountered, a nil value will be returned as a slice along with the error

func FunctionNameWrapper

func FunctionNameWrapper(funcName, colName string) string

FunctionNameWrapper returns a wrapper name with a given function name and a column name

func GenerateRandomSeries

func GenerateRandomSeries(n uint64, range_ uint64, seed int64, withReplacement bool) []int

GenerateRandomSeries will generate n number of random integer values where n is in between [0, range_] using the seed value provided.

If withReplacement is set to true, the sample will contain duplicate values. And if withReplacement is set to false and if the range_ is lower than n, then the returned sample will contain number of elements equal to the range_.

func GetFunctionName

func GetFunctionName(i interface{}) string

GetFunctionName will return the function name of the provided function

func GetRealSizeOf

func GetRealSizeOf(v interface{}) int

GetRealSizeOf returns the number of bytes occupied by a given interface

func IsTimeSet

func IsTimeSet(t time.Time) bool

IsTimeSet checks if time is actually set or has been added by Go

func LinearSearch

func LinearSearch(element interface{}, arr []interface{}) int

LinearSearch would search for the element in the given array and if the element is found it will return the index of the first occurrence in which it is found. If the element is not present it will return -1.

Use ToInterfaceFrom functions to quickly convert slices into interface slices to be used by the function.

Panics, if non-comparable elements are found

func MaxIntSlice

func MaxIntSlice(nums []int) int

MaxIntSlice returns the maximum element of a given int array

func Range

func Range(low, high, step int) []int

Range is a helper function which generates a sequence of numbers starting from the given start integer to the stop integer by the increment of the step integer.

Panics if the step value is incorrectly specified.

func RepeatIntoSlice

func RepeatIntoSlice(s interface{}, n int) []interface{}

RepeatIntoSlice takes in any empty interface element and a number of times it needs to be repeated. It will return a slice of nil interfaces instead of a compact string, as the Repeat method in strings package.

func ReverseArray

func ReverseArray(arr []interface{}) []interface{}

ReverseArray reverses the given slice

func ToIntArray

func ToIntArray(arr []interface{}) []int

ToIntArray converts an array of empty interfaces to an int array

func ToInterfaceFromInt

func ToInterfaceFromInt(arr []int) []interface{}

ToInterfaceFromInt converts an array of int array to an empty interface array

func ToInterfaceFromString

func ToInterfaceFromString(arr []string) []interface{}

ToInterfaceFromString converts an array of string array to an empty interface array

func ValueCounts

func ValueCounts(arr []interface{}) map[interface{}]int

ValueCounts will find the duplicate elements from a given array of empty interfaces and will return a map containing a value count for each unique elements

Types

type Predicate

type Predicate func(element interface{}) (bool, error)

Predicate is the definition of a function which takes in any element and returns a boolean

Jump to

Keyboard shortcuts

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