mcutils

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2023 License: MIT Imports: 19 Imported by: 0

README

mcutils | github.com/abbeymart/mcutils

  • Shared and common utility functions
  • Math functions and methods
  • Statistical functions and methods
  • Collection functions and methods
  • Data analytics, functions and methods
  • Artificial Intelligence and Machine Learning functions and methods

Documentation

Index

Constants

View Source
const (
	DefaultLanguage = "en-US"
)

Variables

View Source
var PermittedSeparators = []string{" ", "_", "__", ".", "|"}

Functions

func AccessAllowed added in v0.2.0

func AccessAllowed(accessList []string, item string) bool

func AddMatrices added in v0.2.0

func AddMatrices[T float64 | int64](matrix1 [][]T, matrix2 [][]T, result [][]T) error

AddMatrices function adds two matrices of the same dimensions.

func AddMultipleMatrices added in v0.2.0

func AddMultipleMatrices[T float64 | int64](matrices [][][]T, result [][]T) error

AddMultipleMatrices function [tensor] adds multiple matrices of the same dimensions.

func AddScalarMatrix added in v0.2.0

func AddScalarMatrix[T float64 | int64](matrix [][]T, scalar T, result [][]T) error

AddScalarMatrix function adds a scalar Value to the matrix/matrices.

func All added in v0.1.7

func All[T ValueType](arr []T, testFunc TestFuncType[T]) bool

All function determines if all the slice-values satisfies the testFunc.

func Any added in v0.1.7

func Any[T ValueType](arr []T, testFunc TestFuncType[T]) bool

Any function determines if one or more of the slice-values satisfies the testFunc.

func ArrayContains

func ArrayContains[T ValueType](arr []T, str T) bool

ArrayContains check if a slice of generic type T contains/includes a Value of type T (for string, it's case-insensitive)

func ArrayContainsCaseSensitive added in v0.2.0

func ArrayContainsCaseSensitive[T ValueType](arr []T, str T) bool

ArrayContainsCaseSensitive check if a slice of generic type T contains/includes a Value of type T (for string, it's case-sensitive)

func ArrayFloatContains added in v0.1.7

func ArrayFloatContains(arr []float64, str float64) bool

ArrayFloatContains check if a slice of int contains/includes a float Value

func ArrayIntContains

func ArrayIntContains(arr []int, val int) bool

ArrayIntContains check if a slice of int contains/includes an int Value

func ArrayMapToMapUnderscore added in v0.1.9

func ArrayMapToMapUnderscore(rec interface{}) ([]map[string]interface{}, error)

ArrayMapToMapUnderscore converts slice of map to map with underscore keys/fields.

func ArrayMapToStruct added in v0.1.9

func ArrayMapToStruct(actParams []map[string]interface{}, recs interface{}) (interface{}, error)

ArrayMapToStruct converts []map/actParams to []struct/model-type

func ArrayStringContains

func ArrayStringContains(arr []string, val string) bool

ArrayStringContains check if a slice of string contains/includes a string Value, case-insensitive

func ArrayStringContainsCaseSensitive added in v0.2.0

func ArrayStringContainsCaseSensitive(arr []string, val string) bool

ArrayStringContainsCaseSensitive check if a slice of string contains/includes a string Value, case-sensitive

func ArrayToSQLStringValues added in v0.1.9

func ArrayToSQLStringValues(arr []string) string

ArrayToSQLStringValues transforms a slice of string to SQL-string-formatted-values

func CaseFieldToUnderscore added in v0.2.0

func CaseFieldToUnderscore(caseString string) string

CaseFieldToUnderscore transforms camelCase or PascalCase name to underscore name, in lowercase

func Classify

func Classify()

func ComparePassword added in v0.2.0

func ComparePassword(userPassword string, inputPassword string, cryptCode string) (bool, error)

func ComparePassword2 added in v0.2.0

func ComparePassword2(userPassword string, inputPassword string, cryptCode string) (bool, error)

func ComputeTaskDuration added in v0.1.9

func ComputeTaskDuration(start time.Time, end time.Time) int64

ComputeTaskDuration computes the task interval in microseconds

func ConvertByteSliceToBase64Str added in v0.1.9

func ConvertByteSliceToBase64Str(fileContent []byte) string

ConvertByteSliceToBase64Str converts slice of byte to base64-string type.

func ConvertJsonBase64StringToMap added in v0.1.9

func ConvertJsonBase64StringToMap(base64Str interface{}) (map[string]interface{}, error)

ConvertJsonBase64StringToMap converts the db-json-string-Value to the map-type On success, returns the resulting map-Value.

func ConvertJsonBase64StringToTypeValue added in v0.1.9

func ConvertJsonBase64StringToTypeValue(base64Str interface{}, typePointer interface{}) (interface{}, error)

ConvertJsonBase64StringToTypeValue converts the db-json-string-Value to the base-type. On success, store and returns the transformed/converted Value to the base-type address (typePointer).

func ConvertJsonStringToMapValue added in v0.1.9

func ConvertJsonStringToMapValue(jsonStr string) (map[string]interface{}, error)

ConvertJsonStringToMapValue converts the db-json-string-Value to the map-type. Returns map Value on success, or on error, returns map nil-Value and error.

func ConvertJsonStringToTypeValue added in v0.1.9

func ConvertJsonStringToTypeValue(jsonStr string, typePointer interface{}) error

ConvertJsonStringToTypeValue converts the db-json-string-Value to the base-type. On success, store the transformed/converted Value to the base-type address (typePointer).

func ConvertStringToBase64Str added in v0.1.9

func ConvertStringToBase64Str(fileContent string) string

ConvertStringToBase64Str converts string Value to slice of byte.

func CurrencyNumFormatter added in v0.2.0

func CurrencyNumFormatter(num *big.Float, currency string, precision int) (string, error)

CurrencyNumFormatter format a number Value based on the specified currency and precision

func DivideScalarMatrix added in v0.2.0

func DivideScalarMatrix[T float64 | int64](matrix [][]T, scalar T, result [][]T) error

DivideScalarMatrix function the matrix/matrices by the scalar Value.

func EncryptPassword added in v0.2.0

func EncryptPassword(newPassword string, cryptCode string) (string, error)

func ExcludeEmptyIdFields added in v0.1.9

func ExcludeEmptyIdFields(recs []map[string]interface{}) []map[string]interface{}

ExcludeEmptyIdFields excludes fields with name id or ending with Id/ID/iD, with zero Value(""). Return the map record with id fields removed.

func ExcludeEmptyIdFromMapRecord added in v0.1.9

func ExcludeEmptyIdFromMapRecord(rec map[string]interface{}) map[string]interface{}

ExcludeEmptyIdFromMapRecord excludes id field with zero Value(""). Return the map record with id fields removed.

func ExcludeFieldFromMapRecord added in v0.1.9

func ExcludeFieldFromMapRecord(rec map[string]interface{}, field string) map[string]interface{}

ExcludeFieldFromMapRecord excludes the specified field name from the map record. Return the map record with the specified field removed.

func ExitOnError

func ExitOnError(err error)

func FactNumGen added in v0.2.0

func FactNumGen(num uint, factChannel chan<- int)

FactNumGen function generates series of the factorial Value of 1 to num.

func Factorial added in v0.2.0

func Factorial(num uint) int

Factorial function returns the factorial Value of 1 to num, using number-generator via channel.

func FactorialGen2

func FactorialGen2(num uint) int

FactorialGen2 function returns the factorial Value of 1 to num, using simple iteration method.

func FactorialTail

func FactorialTail(num uint, acc uint) uint

FactorialTail function returns the factorial Value from 1 to the specified limit (num). Accumulator Value should be set to 1 (default)

func FiboArray

func FiboArray(num uint, result [][]uint)

FiboArray function returns the slice of pairs of fibonacci numbers.

func FiboSeries

func FiboSeries(num uint, fiboChannel chan<- uint)

FiboSeries function generates series of fibonacci numbers up to the specified limit (num).

func FiboTail

func FiboTail(num int, current int, next int) int

FiboTail function returns last fibonacci numbers up to the limit (num). current and next parameters should be set to 0/1? (default) - TODO: review/clarify/test.

func Fibos added in v0.1.7

func Fibos(num uint) []uint

Fibos function returns slice of fibonacci numbers from 1 up to the specified limit (num).

func Filter

func Filter[T ValueType](arr []T, filterFunc func(T) bool, result []T)

Filter function returns the filtered-slice-Value, of type T, based on the filterFunc [generic].

func FilterGen

func FilterGen[T ValueType](arr []T, filterFunc func(T) bool, filterChan chan<- T)

FilterGen function returns series filtered-Value, of type T, based on the filterFunc [generic].

func GeometricMean added in v0.2.0

func GeometricMean[T Number](arr []T) float64

GeometricMean function returns the geometric mean of a slice of type float.

func GetHashValue added in v0.2.0

func GetHashValue(info interface{}, cryptCode string) (string, error)

func GetLanguage

func GetLanguage(userLang string) string

GetLanguage returns the specified user-language or defaultLanguage as default

func GetParamsMessage

func GetParamsMessage(msgObject MessageObject) mcresponse.ResponseMessage

GetParamsMessage compose the message-object into mcresponse.ResponseMessage.

func Index added in v0.1.7

func Index[T ValueType](arr []T, val T) int

Index functions returns the index of the specified Value (for string, it's case-insensitive)

func IndexCaseSensitive added in v0.2.0

func IndexCaseSensitive[T ValueType](arr []T, val T) int

IndexCaseSensitive functions returns the index of the specified Value (for string, it's case-sensitive)

func Interval added in v0.2.0

func Interval[T Number](arr []T) float64

Interval calculates the width/interval of the sample data size

func IsLeapYear added in v0.2.0

func IsLeapYear(year int) bool

IsLeapYear determines if a given year is a leap year

func IsPrime

func IsPrime(n int) bool

IsPrime function determines if the number(n) is a prime number.

func JsonToStruct added in v0.1.9

func JsonToStruct(jsonRec []byte, rec interface{}) error

JsonToStruct converts json input, in []byte, to the equivalent struct data type specification rec must be a pointer to a type matching the jsonRec

func Knn

func Knn()

func Map

func Map[T ValueType](arr []T, mapFunc func(T) T, result []T)

Map function map slice of type T, by the mapFunc.

func MapFloat added in v0.1.7

func MapFloat(arr []float64, mapFunc func(float64) float64, result []float64)

MapFloat function returns the mapped-slice-Value, of type float64, based on the mapFunc.

func MapGen

func MapGen[T ValueType](arr []T, mapFunc func(T) T, mapChan chan<- T)

MapGen function generates series of map Value of type T and send to the mapChan channel.

func MapInt

func MapInt(arr []int, mapFunc func(int) int, result []int)

MapInt function returns the mapped-slice-Value of type int, based on the mapFunc.

func MapString added in v0.1.7

func MapString(arr []string, mapFunc func(string) string, result []string)

MapString function returns the mapped-slice-Value, of type string, based on the mapFunc.

func MapToMapUnderscore added in v0.1.9

func MapToMapUnderscore(rec interface{}) (map[string]interface{}, error)

MapToMapUnderscore converts map camelCase-fields to underscore-fields

func MapToStruct added in v0.1.9

func MapToStruct(mapRecord map[string]interface{}, rec interface{}) (interface{}, error)

MapToStruct converts map to struct

func MapUnderscoreToMapCamelCase added in v0.2.0

func MapUnderscoreToMapCamelCase(rec interface{}, sep string) (map[string]interface{}, error)

MapUnderscoreToMapCamelCase converts map underscore-fields to camelCase-fields

func Max

func Max[T Number](arr []T) T

Max function returns the maximum Value from a slice of type T (int or float).

func Mean

func Mean[T Number](arr []T) float64

Mean function returns the mean or average Value from a slice of type float.

func MeanSquareError

func MeanSquareError()

func MeanSquareRootError

func MeanSquareRootError()

func Median

func Median[T Number](arr []T) float64

Median function returns the mid or median Value from a slice of type float.

func Min

func Min[T Number](arr []T) T

Min function returns the minimum Value from a slice of type T (int or float).

func MinMax

func MinMax[T Number](arr []T) (min T, max T)

MinMax function returns the minimum amd maximum values from a slice of type T (int or float).

func MultiplyMatrices added in v0.2.0

func MultiplyMatrices[T float64 | int64](matrix1 [][]T, matrix2 [][]T, result [][]T) error

MultiplyMatrices function multiply two matrices. The number of rows in matrix1 sub-matrices must be the same as the number of columns in matrix2.

func MultiplyMatrix added in v0.2.0

func MultiplyMatrix[T float64 | int64](matrix1 []T, matrix2 [][]T, result []T) error

MultiplyMatrix function multiply two matrices. The matrix1 single slice length must be the same as the number of columns in matrix2/sub-matrices.

func MultiplyScalarMatrix added in v0.2.0

func MultiplyScalarMatrix[T float64 | int64](matrix [][]T, scalar T, result [][]T) error

MultiplyScalarMatrix function multiply a scalar Value with the matrix/matrices.

func NBayes

func NBayes()

func NaturalNumbers

func NaturalNumbers(num uint, cntChannel chan<- uint)

NaturalNumbers function generates series positive numbers from 0 up to specified limit (num).

func NaturalNumbersGen

func NaturalNumbersGen(num uint, naturalChan chan<- uint)

NaturalNumbersGen function generates finite natural numbers.

func NaturalNumbersGenInf

func NaturalNumbersGenInf(naturalChan chan<- uint, stopFunc func() bool)

NaturalNumbersGenInf function generates infinite natural numbers.

func NumFormatter added in v0.2.0

func NumFormatter(num *big.Float, precision int) (string, error)

NumFormatter format a number Value based on the specified precision

func PanicOnError

func PanicOnError(err error)

func ParseRawValues added in v0.1.9

func ParseRawValues(rawValues [][]byte) ([]interface{}, error)

ParseRawValues process the raw rows/records from SQL-query

func PopulationStandardDeviation added in v0.2.0

func PopulationStandardDeviation[T Number](arr []T) float64

PopulationStandardDeviation function returns the standard-deviation Value from a population/complete-data of slice of type float.

func PrimeNumbers added in v0.1.7

func PrimeNumbers(num int) (pNums []int)

PrimeNumbers function returns the prime numbers up to the limit if num.

func Pythagoras

func Pythagoras(limit uint) [][]uint

Pythagoras function returns the number pairs and hypothesis values.

func PythagorasGen

func PythagorasGen(limit uint, pythagorasChan chan []uint)

PythagorasGen function generates series the number pairs and hypothesis values.

func RandomNumbers added in v0.1.9

func RandomNumbers(n int) string

RandomNumbers generates random numbers using rand.Perm and returns []int as string

func RandomString added in v0.1.9

func RandomString(n int) string

RandomString generates random string of characters and numbers

func Range added in v0.2.0

func Range[T Number](arr []T) T

Range function returns the range of the slice type of float.

func ReverseArray

func ReverseArray[T ValueType](arr []T, result []T)

ReverseArray returns the reverse values of the specified array/slice [generic type]

func ReverseArrayFloat

func ReverseArrayFloat(arr []float64, result []float64)

ReverseArrayFloat returns the reverse values of the specified array/slice of float64.

func ReverseArrayFloatGen

func ReverseArrayFloatGen(arr []float64, arrChan chan<- float64)

ReverseArrayFloatGen sequentially generates reverse values of the specified array/slice of float64.

func ReverseArrayGenerator added in v0.2.0

func ReverseArrayGenerator[T ValueType](arr []T, arrChan chan<- T)

ReverseArrayGenerator sequentially generates reverse values of the specified array/slice [generic]

func ReverseArrayInt

func ReverseArrayInt(arr []int, result []int)

ReverseArrayInt returns the reverse values of the specified array/slice of int.

func ReverseArrayIntGen

func ReverseArrayIntGen(arr []int, arrChan chan<- int)

ReverseArrayIntGen sequentially generates reverse values of the specified array/slice of int.

func SampleStandardDeviation added in v0.2.0

func SampleStandardDeviation[T Number](arr []T) float64

SampleStandardDeviation function returns the standard-deviation Value from a sample-data of slice of type float.

func SeparatorFieldToCamelCase added in v0.2.0

func SeparatorFieldToCamelCase(text string, sep string) (string, error)

SeparatorFieldToCamelCase transforms a separated/underscore name to camel-case name

func SeparatorFieldToPascalCase added in v0.2.0

func SeparatorFieldToPascalCase(text string, sep string) (string, error)

SeparatorFieldToPascalCase transforms a separated/underscore field-name to pascal-case

func ShortString

func ShortString(str string, maxLength uint) string

ShortString returns part of string, based on the specified maxLength

func StringToBool

func StringToBool(val string) bool

StringToBool returns the boolean Value of the specified string-Value

func StructToFieldValues added in v0.1.9

func StructToFieldValues(rec interface{}) (tableFields []string, fieldValues []interface{}, err error)

StructToFieldValues converts struct to record fields(underscore) and associated values - columns and values.

func StructToMap added in v0.1.9

func StructToMap(rec interface{}) (map[string]interface{}, error)

StructToMap function transforms struct to map. Map keys match the json-fields of the struct data.

func StructToMapTag added in v0.2.0

func StructToMapTag(rec interface{}, tag string) (map[string]interface{}, error)

StructToMapTag function converts struct to map (with key of tag/underscore name), for crud-db-table-record

func StructToMapUnderscore added in v0.1.9

func StructToMapUnderscore(rec interface{}) (map[string]interface{}, error)

StructToMapUnderscore converts struct to map (underscore_fields), for crud-db-table-record

func StructToMapUnderscoreData added in v0.2.0

func StructToMapUnderscoreData(rec interface{}) (map[string]interface{}, error)

StructToMapUnderscoreData transform a struct data type to the map[string]interface{} Value type, camelCase fields. map keys are converted to underscore types to match database-table-field/columns specs

func SubtractMatrices added in v0.2.0

func SubtractMatrices[T float64 | int64](matrix1 [][]T, matrix2 [][]T, result [][]T) error

SubtractMatrices function subtract two matrices of the same dimensions.

func SubtractMultipleMatrices added in v0.2.0

func SubtractMultipleMatrices[T float64 | int64](matrices [][][]T, result [][]T) error

SubtractMultipleMatrices function [tensor] subtract multiple matrices of the same dimensions.

func SubtractScalarMatrix added in v0.2.0

func SubtractScalarMatrix[T float64 | int64](matrix [][]T, scalar T, result [][]T) error

SubtractScalarMatrix function subtracts a scalar Value from the matrix/matrices.

func TagField added in v0.1.9

func TagField(rec interface{}, fieldName string, tag string) (string, error)

TagField returns the field-tag (e.g. table-column-name) for mcorm/db/other tag, for the specified struct data fieldName.

func Take

func Take[T ValueType](num uint, arr []T, result []T)

Take function returns num of the arr slice of type T [generic].

func TakeGen

func TakeGen[T ValueType](num uint, arr []T, takeChan chan<- T)

TakeGen function returns num series of values, of type T [generic].

func TransposeMatrix added in v0.2.0

func TransposeMatrix[T float64 | int64](matrix [][]T, result [][]T) error

TransposeMatrix function transpose the matrix - swap rows and columns, i.e. rotate the matrix around it's diagonal.

func TypeOf added in v0.1.9

func TypeOf(rec interface{}) reflect.Type

func Variance

func Variance[T Number](arr []T) float64

Variance function returns the variance of the mean-square-Value from a slice of type float.

Types

type ArrayOfFloat

type ArrayOfFloat []float64

func (ArrayOfFloat) SetOfFloat added in v0.2.0

func (val ArrayOfFloat) SetOfFloat() []float64

type ArrayOfInt

type ArrayOfInt []int

func (ArrayOfInt) SetOfInt added in v0.2.0

func (val ArrayOfInt) SetOfInt() []int

type ArrayOfString

type ArrayOfString []string

func (ArrayOfString) SetOfString added in v0.2.0

func (val ArrayOfString) SetOfString() []string

type ArrayValue

type ArrayValue[T ValueType] []T

func (ArrayValue[T]) Counter added in v0.2.0

func (val ArrayValue[T]) Counter() CounterResult[T]

Counter method returns the unique counts of the specified array/slice values[int, float, string and bool]

func (ArrayValue[T]) Set added in v0.2.0

func (val ArrayValue[T]) Set() []T

Set method returns the slice of set values for a generic type T

type BiConsumer added in v0.2.0

type BiConsumer[T ValueType, U ValueType] func(val1 T, val2 U)

type BiFunction added in v0.2.0

type BiFunction[T ValueType, U ValueType, R ValueType] func(val1 T, val2 U) R

type BinaryOperator added in v0.2.0

type BinaryOperator[T ValueType] func(val1 T, val2 T) T

type BinaryPredicate added in v0.2.0

type BinaryPredicate[T ValueType, U ValueType] func(val1 T, val2 U) bool

type BoolSliceType added in v0.2.0

type BoolSliceType struct {
	Value []bool `json:"Value"`
}

type BoolType added in v0.2.0

type BoolType struct {
	Value bool `json:"value"`
}

type Comparator added in v0.2.0

type Comparator[T ValueType] func(val1 T, val2 T) int

type Consumer added in v0.2.0

type Consumer[T ValueType] func(val T)

type CounterObjectValue added in v0.2.0

type CounterObjectValue[T map[string]interface{} | struct{}] struct {
	Count int
	Value T
}

type CounterResult added in v0.2.0

type CounterResult[T ValueType] map[string]CounterValue[T]

type CounterValue added in v0.2.0

type CounterValue[T ValueType] struct {
	Count int `json:"count"`
	Value T   `json:"value"`
}

func Mode added in v0.2.0

func Mode[T Number](arr []T) []CounterValue[T]

Mode function returns the mode(most frequently occurring Value(s)) of a slice of type float.

type DataCount

type DataCount map[string]int

type FloatPredicate added in v0.2.0

type FloatPredicate func(val float64) bool

type FloatSliceType added in v0.2.0

type FloatSliceType struct {
	Value []float64 `json:"value"`
}

func (*FloatSliceType) ArrayFloatContains added in v0.2.0

func (arr *FloatSliceType) ArrayFloatContains(queryVal float64) bool

ArrayFloatContains method check if a slice of int contains/includes a float Value

func (*FloatSliceType) MapFloat added in v0.2.0

func (arr *FloatSliceType) MapFloat(mapFunc func(float64) float64, result []float64)

MapFloat method returns the mapped-slice-Value, of type float64, based on the mapFunc.

func (*FloatSliceType) ReverseArrayFloat added in v0.2.0

func (arr *FloatSliceType) ReverseArrayFloat(result []float64)

ReverseArrayFloat returns the reverse values of the specified array/slice of float64.

func (*FloatSliceType) ReverseArrayFloatGen added in v0.2.0

func (arr *FloatSliceType) ReverseArrayFloatGen(arrChan chan<- float64)

ReverseArrayFloatGen sequentially generates reverse values of the specified array/slice of float64.

type FloatType added in v0.2.0

type FloatType struct {
	Value float64 `json:"value"`
}

type FrequencyResult added in v0.2.0

type FrequencyResult struct {
	Result   []FrequencyValue `json:"result"`
	Interval float64          `json:"interval"`
}

func Frequency added in v0.2.0

func Frequency[T Number](arr []T, interval float64, valueLabel string) FrequencyResult

Frequency function returns the frequency / occurrence of a slice of type float.

type FrequencyValue added in v0.2.0

type FrequencyValue struct {
	Label     string  `json:"label"`
	Frequency int     `json:"frequency"`
	Value     float64 `json:"value"`
}

type Function added in v0.2.0

type Function[T ValueType, R ValueType] func(val T) R

type GenericSliceType added in v0.2.0

type GenericSliceType[T ValueType] struct {
	Value []T `json:"Value"`
}

func (*GenericSliceType[T]) All added in v0.2.0

func (arr *GenericSliceType[T]) All(testFunc TestFuncType[T]) bool

All method determines if all the slice-values satisfies the testFunc.

func (*GenericSliceType[T]) Any added in v0.2.0

func (arr *GenericSliceType[T]) Any(testFunc TestFuncType[T]) bool

Any method determines if one or more of the slice-values satisfies the testFunc.

func (*GenericSliceType[T]) ArrayContains added in v0.2.0

func (arr *GenericSliceType[T]) ArrayContains(queryVal T) bool

ArrayContains method check if a slice of generic type T contains/includes a Value of type T (for string, it's case-insensitive)

func (*GenericSliceType[T]) ArrayContainsCaseSensitive added in v0.2.0

func (arr *GenericSliceType[T]) ArrayContainsCaseSensitive(str T) bool

ArrayContainsCaseSensitive check if a slice of generic type T contains/includes a Value of type T (for string, it's case-sensitive)

func (*GenericSliceType[T]) Filter added in v0.2.0

func (arr *GenericSliceType[T]) Filter(filterFunc func(T) bool, result []T)

Filter method returns the filtered-slice-Value, of type T, based on the filterFunc [generic].

func (*GenericSliceType[T]) FilterGen added in v0.2.0

func (arr *GenericSliceType[T]) FilterGen(filterFunc func(T) bool, filterChan chan<- T)

FilterGen method returns series filtered-Value, of type T, based on the filterFunc [generic].

func (*GenericSliceType[T]) Index added in v0.2.0

func (arr *GenericSliceType[T]) Index(queryVal T) int

Index method returns the index of the specified Value (for string, it's case-insensitive)

func (*GenericSliceType[T]) IndexCaseSensitive added in v0.2.0

func (arr *GenericSliceType[T]) IndexCaseSensitive(val T) int

IndexCaseSensitive method returns the index of the specified Value (for string, it's case-sensitive)

func (*GenericSliceType[T]) Map added in v0.2.0

func (arr *GenericSliceType[T]) Map(mapFunc func(T) T, result []T)

Map method returns the mapped-slice-Value, of type T, based on the mapFunc [generic].

func (*GenericSliceType[T]) MapGen added in v0.2.0

func (arr *GenericSliceType[T]) MapGen(mapFunc func(T) T, mapChan chan<- T)

MapGen returns series of the mapped-Value, of type T, based on the mapFunc [generic].

func (*GenericSliceType[T]) ReverseArray added in v0.2.0

func (arr *GenericSliceType[T]) ReverseArray(result []T)

ReverseArray method returns the reverse values of the specified array/slice [generic type]

func (*GenericSliceType[T]) ReverseArrayGenerator added in v0.2.0

func (arr *GenericSliceType[T]) ReverseArrayGenerator(arrChan chan<- T)

ReverseArrayGenerator sequentially generates reverse values of the specified array/slice [generic]

func (*GenericSliceType[T]) Take added in v0.2.0

func (arr *GenericSliceType[T]) Take(num uint, result []T)

Take method returns num of the arr slice of type T [generic].

func (*GenericSliceType[T]) TakeGen added in v0.2.0

func (arr *GenericSliceType[T]) TakeGen(num uint, takeChan chan<- T)

TakeGen method returns num series of values, of type T [generic].

type GenericType added in v0.2.0

type GenericType[T ValueType] struct {
	Value T `json:"value"`
}

type IntPredicate added in v0.2.0

type IntPredicate func(val int) bool

type IntSliceType added in v0.2.0

type IntSliceType struct {
	Value []int `json:"Value"`
}

func (*IntSliceType) ArrayIntContains added in v0.2.0

func (arr *IntSliceType) ArrayIntContains(queryVal int) bool

ArrayIntContains method check if a slice of int contains/includes an int Value

func (*IntSliceType) MapInt added in v0.2.0

func (arr *IntSliceType) MapInt(mapFunc func(int) int, result []int)

MapInt method returns the mapped-slice-Value of type int, based on the mapFunc.

func (*IntSliceType) ReverseArrayInt added in v0.2.0

func (arr *IntSliceType) ReverseArrayInt(result []int)

ReverseArrayInt method returns the reverse values of the specified array/slice of int.

func (*IntSliceType) ReverseArrayIntGen added in v0.2.0

func (arr *IntSliceType) ReverseArrayIntGen(arrChan chan<- int)

ReverseArrayIntGen sequentially generates reverse values of the specified array/slice of int.

type IntType added in v0.2.0

type IntType struct {
	Value int `json:"value"`
}

type Locale

type Locale map[string]interface{}

func GetLocale added in v0.2.0

func GetLocale(localeFiles LocaleFilesType, options LocaleOptions) Locale

GetLocale function returns the locale for the specified language

type LocaleContent

type LocaleContent map[string]interface{}

type LocaleFilesType added in v0.2.0

type LocaleFilesType map[string]Locale // key => language ("en-US", "en-CA", "yoruba", "fr-CA", "fr-FR" etc.

type LocaleFunc added in v0.2.0

type LocaleFunc func(val interface{}) interface{}

type LocaleOptions

type LocaleOptions struct {
	LocaleType string
	Language   string
}

type LocaleValueType added in v0.2.0

type LocaleValueType interface {
	ValueType | LocaleFunc
}

type MessageObject

type MessageObject map[string]string

type Number added in v0.1.9

type Number interface {
	int | int64 | float64 | float32
}

type NumberPredicate added in v0.2.0

type NumberPredicate[T Number] func(val T) bool

type ObjectCounterResult added in v0.2.0

type ObjectCounterResult[T map[string]interface{} | struct{}] map[string]CounterObjectValue[T]

type ObjectType added in v0.2.0

type ObjectType map[string]interface{}

type Predicate added in v0.2.0

type Predicate[T ValueType] func(val T) bool

type QuartilesType added in v0.2.0

type QuartilesType struct {
	Min   float64 `json:"min"` // Lowest value
	Q1    float64 `json:"q1"`
	Q2    float64 `json:"q2"` // Median
	Q3    float64 `json:"q3"`
	Q4    float64 `json:"q4"` // Highest value, Max
	IQR   float64 `json:"IQR"`
	Max   float64 `json:"max"`   // Highest value, Q4
	Range float64 `json:"range"` // Q3 - Q1
}

func Deciles added in v0.2.0

func Deciles[T Number](arr []T) QuartilesType

Deciles returns slice-values that separate the data into 10 equal parts (quantiles). TODO: review/complete. Examples: 10%, 20%[Q2], 30%[Q3]... 100%

func IQRange added in v0.2.0

func IQRange[T Number](arr []T) QuartilesType

IQRange InterQuartileRange returns the difference between the first and third quartiles (Q1 and Q3), including quartile-values[Q0/min, Q1/25%, Q2/50%(median), Q3/75% & Q4/max].

func Percentiles added in v0.2.0

func Percentiles[T Number](arr []T) QuartilesType

Percentiles returns slice-values that separate the data into 100 equal parts (quantiles). TODO: review/complete. Examples: 1%, 2%, 3%... 100%.

type SliceObjectType added in v0.2.0

type SliceObjectType[T map[string]interface{}] []T

func (SliceObjectType[T]) SliceObjectCounter added in v0.2.0

func (val SliceObjectType[T]) SliceObjectCounter() ObjectCounterResult[T]

SliceObjectCounter method returns the unique counts of the specified array/slice of map[string]interface{} values

type StatFrequencyResult added in v0.2.0

type StatFrequencyResult struct {
	Result   []StatFrequencyValue `json:"result"`
	Interval float64              `json:"interval"`
}

func StatFrequency added in v0.2.0

func StatFrequency[T Number](arr []T, interval float64, valueLabel string) StatFrequencyResult

StatFrequency function returns the frequency / relative / cumulative / relative-cumulative frequencies of a slice of type float.

type StatFrequencyValue added in v0.2.0

type StatFrequencyValue struct {
	Label                       string  `json:"label"`
	Value                       float64 `json:"value"`
	Frequency                   int     `json:"frequency"`
	RelativeFrequency           float64 `json:"relativeFrequency"`
	CumulativeFrequency         int     `json:"cumulativeFrequency"`
	CumulativeRelativeFrequency float64 `json:"cumulativeRelativeFrequency"`
}

type StringPredicate added in v0.2.0

type StringPredicate func(val string) bool

type StringSliceType added in v0.2.0

type StringSliceType struct {
	Value []string `json:"value"`
}

func (*StringSliceType) ArrayStringContains added in v0.2.0

func (arr *StringSliceType) ArrayStringContains(queryVal string) bool

ArrayStringContains method check if a slice of string contains/includes a string Value, case-insensitive

func (*StringSliceType) ArrayStringContainsCaseSensitive added in v0.2.0

func (arr *StringSliceType) ArrayStringContainsCaseSensitive(val string) bool

ArrayStringContainsCaseSensitive method check if a slice of string contains/includes a string Value, case-sensitive

func (*StringSliceType) MapString added in v0.2.0

func (arr *StringSliceType) MapString(mapFunc func(string) string, result []string)

MapString method returns the mapped-slice-Value, of type string, based on the mapFunc.

type StringType added in v0.2.0

type StringType struct {
	Value string `json:"Value"`
}

type Supplier added in v0.2.0

type Supplier[R ValueType] func() R

type TestFuncType added in v0.2.0

type TestFuncType[T ValueType] func(val T) bool

type UnaryOperator added in v0.2.0

type UnaryOperator[T ValueType] func(val1 T) T

type ValueType added in v0.1.9

type ValueType interface {
	string | int | int64 | float64 | float32 | bool
}

type ValueTypeSlice added in v0.2.0

type ValueTypeSlice interface {
	[]string | int | []int64 | []float64 | float32 | []bool | []map[string]interface{}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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