Documentation ¶
Index ¶
- Constants
- func Any(slice AnySlice, f IterFunc) bool
- func Avg(slice AnySlice) float64
- func FilterBools(in []bool, f func(bool) bool) []bool
- func FilterFloat64s(in []float64, f func(float64) bool) []float64
- func FilterInts(in []int, f func(int) bool) []int
- func FilterStrings(in []string, f func(string) bool) []string
- func JoinAsString(slice AnySlice, sep string) string
- func JoinAsStringWithFormat(slice AnySlice, format, sep string) string
- func MapAnyValueToBool(in []AnyValue, f func(AnyValue) bool) []bool
- func MapAnyValueToFloat64(in []AnyValue, f func(AnyValue) float64) []float64
- func MapAnyValueToInt(in []AnyValue, f func(AnyValue) int) []int
- func MapAnyValueToString(in []AnyValue, f func(AnyValue) string) []string
- func MapBoolToBool(in []bool, f func(bool) bool) []bool
- func MapBoolToFloat64(in []bool, f func(bool) float64) []float64
- func MapBoolToInt(in []bool, f func(bool) int) []int
- func MapBoolToString(in []bool, f func(bool) string) []string
- func MapFloat64ToBool(in []float64, f func(float64) bool) []bool
- func MapFloat64ToFloat64(in []float64, f func(float64) float64) []float64
- func MapFloat64ToInt(in []float64, f func(float64) int) []int
- func MapFloat64ToString(in []float64, f func(float64) string) []string
- func MapIntToBool(in []int, f func(int) bool) []bool
- func MapIntToFloat64(in []int, f func(int) float64) []float64
- func MapIntToInt(in []int, f func(int) int) []int
- func MapIntToString(in []int, f func(int) string) []string
- func MapStringToBool(in []string, f func(string) bool) []bool
- func MapStringToFloat64(in []string, f func(string) float64) []float64
- func MapStringToInt(in []string, f func(string) int) []int
- func MapStringToString(in []string, f func(string) string) []string
- func ReduceAnyValueToBool(in []AnyValue, memo bool, f func(bool, AnyValue) bool) bool
- func ReduceAnyValueToFloat64(in []AnyValue, memo float64, f func(float64, AnyValue) float64) float64
- func ReduceAnyValueToInt(in []AnyValue, memo int, f func(int, AnyValue) int) int
- func ReduceAnyValueToString(in []AnyValue, memo string, f func(string, AnyValue) string) string
- func ReduceBoolToBool(in []bool, memo bool, f func(bool, bool) bool) bool
- func ReduceBoolToFloat64(in []bool, memo float64, f func(float64, bool) float64) float64
- func ReduceBoolToInt(in []bool, memo int, f func(int, bool) int) int
- func ReduceBoolToString(in []bool, memo string, f func(string, bool) string) string
- func ReduceFloat64ToBool(in []float64, memo bool, f func(bool, float64) bool) bool
- func ReduceFloat64ToFloat64(in []float64, memo float64, f func(float64, float64) float64) float64
- func ReduceFloat64ToInt(in []float64, memo int, f func(int, float64) int) int
- func ReduceFloat64ToString(in []float64, memo string, f func(string, float64) string) string
- func ReduceIntToBool(in []int, memo bool, f func(bool, int) bool) bool
- func ReduceIntToFloat64(in []int, memo float64, f func(float64, int) float64) float64
- func ReduceIntToInt(in []int, memo int, f func(int, int) int) int
- func ReduceIntToString(in []int, memo string, f func(string, int) string) string
- func ReduceStringToBool(in []string, memo bool, f func(bool, string) bool) bool
- func ReduceStringToFloat64(in []string, memo float64, f func(float64, string) float64) float64
- func ReduceStringToInt(in []string, memo int, f func(int, string) int) int
- func ReduceStringToString(in []string, memo string, f func(string, string) string) string
- func Reverse(slice AnySlice)
- func Sort(slice AnySlice)
- func SortBy(slice AnySlice, f IterFunc)
- func SumAsFloat64(slice AnySlice) float64
- func SumAsInt(slice AnySlice) int
- type AnySlice
- func ConvertSlice(in AnySlice, outType AnySlice) AnySlice
- func Filter(slice AnySlice, f IterFunc) AnySlice
- func First(slice AnySlice, n int) AnySlice
- func Flatten(slice AnySlice) AnySlice
- func Intersection(a, b AnySlice) AnySlice
- func Last(slice AnySlice, n int) AnySlice
- func Map(slice AnySlice, f IterFunc) AnySlice
- func Uniq(slice AnySlice) AnySlice
- type AnyValue
- func FilterAnyValues(in []AnyValue, f func(AnyValue) bool) []AnyValue
- func Find(slice AnySlice, f IterFunc) (int, AnyValue)
- func GenericMap(in []AnyValue, f func(AnyValue) AnyValue) []AnyValue
- func Group(slice AnySlice, keyFunc IterFunc) AnyValue
- func MapAnyValueToAnyValue(in []AnyValue, f func(AnyValue) AnyValue) []AnyValue
- func MapBoolToAnyValue(in []bool, f func(bool) AnyValue) []AnyValue
- func MapFloat64ToAnyValue(in []float64, f func(float64) AnyValue) []AnyValue
- func MapIntToAnyValue(in []int, f func(int) AnyValue) []AnyValue
- func MapStringToAnyValue(in []string, f func(string) AnyValue) []AnyValue
- func Max(slice AnySlice) AnyValue
- func Min(slice AnySlice) AnyValue
- func Reduce(slice AnySlice, memo AnyValue, f IterFunc) AnyValue
- func ReduceAnyValueToAnyValue(in []AnyValue, memo AnyValue, f func(AnyValue, AnyValue) AnyValue) AnyValue
- func ReduceBoolToAnyValue(in []bool, memo AnyValue, f func(AnyValue, bool) AnyValue) AnyValue
- func ReduceFloat64ToAnyValue(in []float64, memo AnyValue, f func(AnyValue, float64) AnyValue) AnyValue
- func ReduceIntToAnyValue(in []int, memo AnyValue, f func(AnyValue, int) AnyValue) AnyValue
- func ReduceStringToAnyValue(in []string, memo AnyValue, f func(AnyValue, string) AnyValue) AnyValue
- func ToGenericSlice(in AnySlice) []AnyValue
- type Enumerable
- func (e Enumerable) Any(f IterFunc) bool
- func (e Enumerable) Avg() float64
- func (e Enumerable) Convert(sliceType AnySlice) Enumerable
- func (e Enumerable) Filter(f IterFunc) Enumerable
- func (e Enumerable) Find(f IterFunc) (int, AnyValue)
- func (e Enumerable) First(n int) Enumerable
- func (e Enumerable) Flatten() Enumerable
- func (e Enumerable) GenericMap(f func(AnyValue) AnyValue) Enumerable
- func (e Enumerable) GetSlice(slicePtr interface{})
- func (e Enumerable) Group(keyFunc IterFunc) AnyValue
- func (e Enumerable) JoinAsString(sep string) string
- func (e Enumerable) JoinAsStringWithFormat(format, sep string) string
- func (e Enumerable) Last(n int) Enumerable
- func (e Enumerable) Map(f IterFunc) Enumerable
- func (e Enumerable) Max() AnyValue
- func (e Enumerable) Min() AnyValue
- func (e Enumerable) Reduce(memo AnyValue, f IterFunc) AnyValue
- func (e Enumerable) ReduceToFloat64(memo float64, f IterFunc) float64
- func (e Enumerable) ReduceToInt(memo int, f IterFunc) int
- func (e Enumerable) Reverse() Enumerable
- func (e Enumerable) Sort() Enumerable
- func (e Enumerable) SortBy(f IterFunc) Enumerable
- func (e Enumerable) SumAsFloat64() float64
- func (e Enumerable) SumAsInt() int
- func (e Enumerable) ToGeneric() Enumerable
- func (e Enumerable) Uniq() Enumerable
- type IterFunc
Constants ¶
const NotFound = -1
NotFound is returned by `Find` when no matching item is found
Variables ¶
This section is empty.
Functions ¶
func FilterBools ¶
FilterBools returns a slice of bool where `f` returns true
func FilterFloat64s ¶
FilterFloat64s returns a slice of float64 where `f` returns true
func FilterInts ¶
FilterInts returns a slice of int where `f` returns true
func FilterStrings ¶
FilterStrings returns a slice of string where `f` returns true
func JoinAsString ¶
JoinAsString returns a string with each item converted to string and joined with `sep`.
func JoinAsStringWithFormat ¶
JoinAsStringWithFormat returns a string with each item converted to string using the given format string (see fmt.Printf) and joined with `sep`.
func MapAnyValueToBool ¶
MapAnyValueToBool maps a slice of AnyValue to bool
func MapAnyValueToFloat64 ¶
MapAnyValueToFloat64 maps a slice of AnyValue to float64
func MapAnyValueToInt ¶
MapAnyValueToInt maps a slice of AnyValue to int
func MapAnyValueToString ¶
MapAnyValueToString maps a slice of AnyValue to string
func MapBoolToBool ¶
MapBoolToBool maps a slice of bool to bool
func MapBoolToFloat64 ¶
MapBoolToFloat64 maps a slice of bool to float64
func MapBoolToInt ¶
MapBoolToInt maps a slice of bool to int
func MapBoolToString ¶
MapBoolToString maps a slice of bool to string
func MapFloat64ToBool ¶
MapFloat64ToBool maps a slice of float64 to bool
func MapFloat64ToFloat64 ¶
MapFloat64ToFloat64 maps a slice of float64 to float64
func MapFloat64ToInt ¶
MapFloat64ToInt maps a slice of float64 to int
func MapFloat64ToString ¶
MapFloat64ToString maps a slice of float64 to string
func MapIntToBool ¶
MapIntToBool maps a slice of int to bool
func MapIntToFloat64 ¶
MapIntToFloat64 maps a slice of int to float64
func MapIntToInt ¶
MapIntToInt maps a slice of int to int
func MapIntToString ¶
MapIntToString maps a slice of int to string
func MapStringToBool ¶
MapStringToBool maps a slice of string to bool
func MapStringToFloat64 ¶
MapStringToFloat64 maps a slice of string to float64
func MapStringToInt ¶
MapStringToInt maps a slice of string to int
func MapStringToString ¶
MapStringToString maps a slice of string to string
func ReduceAnyValueToBool ¶
ReduceAnyValueToBool reduces a slice of AnyValue to bool
func ReduceAnyValueToFloat64 ¶
func ReduceAnyValueToFloat64(in []AnyValue, memo float64, f func(float64, AnyValue) float64) float64
ReduceAnyValueToFloat64 reduces a slice of AnyValue to float64
func ReduceAnyValueToInt ¶
ReduceAnyValueToInt reduces a slice of AnyValue to int
func ReduceAnyValueToString ¶
ReduceAnyValueToString reduces a slice of AnyValue to string
func ReduceBoolToBool ¶
ReduceBoolToBool reduces a slice of bool to bool
func ReduceBoolToFloat64 ¶
ReduceBoolToFloat64 reduces a slice of bool to float64
func ReduceBoolToInt ¶
ReduceBoolToInt reduces a slice of bool to int
func ReduceBoolToString ¶
ReduceBoolToString reduces a slice of bool to string
func ReduceFloat64ToBool ¶
ReduceFloat64ToBool reduces a slice of float64 to bool
func ReduceFloat64ToFloat64 ¶
ReduceFloat64ToFloat64 reduces a slice of float64 to float64
func ReduceFloat64ToInt ¶
ReduceFloat64ToInt reduces a slice of float64 to int
func ReduceFloat64ToString ¶
ReduceFloat64ToString reduces a slice of float64 to string
func ReduceIntToBool ¶
ReduceIntToBool reduces a slice of int to bool
func ReduceIntToFloat64 ¶
ReduceIntToFloat64 reduces a slice of int to float64
func ReduceIntToInt ¶
ReduceIntToInt reduces a slice of int to int
func ReduceIntToString ¶
ReduceIntToString reduces a slice of int to string
func ReduceStringToBool ¶
ReduceStringToBool reduces a slice of string to bool
func ReduceStringToFloat64 ¶
ReduceStringToFloat64 reduces a slice of string to float64
func ReduceStringToInt ¶
ReduceStringToInt reduces a slice of string to int
func ReduceStringToString ¶
ReduceStringToString reduces a slice of string to string
func Sort ¶
func Sort(slice AnySlice)
Sort requires a slice with elements that are some sort of int or string
func SortBy ¶
SortBy sorts a slice by the return value of function which is given each item in the slice. The function's return value must be a `string` or `int`.
func SumAsFloat64 ¶
SumAsFloat64 will sum items in slice and return value as float64.
Types ¶
type AnySlice ¶
type AnySlice interface{}
AnySlice represents a slice with elements of any type
func ConvertSlice ¶
func Filter ¶
Filter takes a slice of any type and a function which takes that type as a paramter and returns a bool to indicate whether that value should be included in the output.
func Intersection ¶
Intersection returns a new slice containing only the items present in both slices
type AnyValue ¶
type AnyValue interface{}
AnyValue represents any value
func FilterAnyValues ¶
FilterAnyValues returns a slice of AnyValue where `f` returns true
func Find ¶
Find calls `f` for each item in the slice until `f` returns `true`. If an item is found, it returns the index of that item and the item itself. If none are found, it returns `NotFound, nil`.
func GenericMap ¶
GenericMap does not use reflection, but does require the input slice to be of `[]AnyValue` type, and requires the function to do type assertions as necessary. var GenericMap = MapAnyValueToAnyValue
func Group ¶
Group groups the slice by the return value of `keyFunc`. It returns a map where the keys are the return values of `keyFunc`, and the values are slices of the same type as the given slice
func MapAnyValueToAnyValue ¶
MapAnyValueToAnyValue maps a slice of AnyValue to AnyValue
func MapBoolToAnyValue ¶
MapBoolToAnyValue maps a slice of bool to AnyValue
func MapFloat64ToAnyValue ¶
MapFloat64ToAnyValue maps a slice of float64 to AnyValue
func MapIntToAnyValue ¶
MapIntToAnyValue maps a slice of int to AnyValue
func MapStringToAnyValue ¶
MapStringToAnyValue maps a slice of string to AnyValue
func Reduce ¶
Reduce takes a slice of some type, a memo value of some other type, and a function which takes the memo type and the slice type as parameters and returns the memo type. Reduce returns the final memo.
func ReduceAnyValueToAnyValue ¶
func ReduceAnyValueToAnyValue(in []AnyValue, memo AnyValue, f func(AnyValue, AnyValue) AnyValue) AnyValue
ReduceAnyValueToAnyValue reduces a slice of AnyValue to AnyValue
func ReduceBoolToAnyValue ¶
ReduceBoolToAnyValue reduces a slice of bool to AnyValue
func ReduceFloat64ToAnyValue ¶
func ReduceFloat64ToAnyValue(in []float64, memo AnyValue, f func(AnyValue, float64) AnyValue) AnyValue
ReduceFloat64ToAnyValue reduces a slice of float64 to AnyValue
func ReduceIntToAnyValue ¶
ReduceIntToAnyValue reduces a slice of int to AnyValue
func ReduceStringToAnyValue ¶
ReduceStringToAnyValue reduces a slice of string to AnyValue
func ToGenericSlice ¶
type Enumerable ¶
type Enumerable struct {
Slice AnySlice
}
Enumerable makes it easy to map, filter, reduce, etc using any slice
func (Enumerable) Any ¶
func (e Enumerable) Any(f IterFunc) bool
Any returns true if the given function returns true for any items in the slice
func (Enumerable) Avg ¶
func (e Enumerable) Avg() float64
Avg returns the average value of items in the slice
func (Enumerable) Convert ¶
func (e Enumerable) Convert(sliceType AnySlice) Enumerable
func (Enumerable) Filter ¶
func (e Enumerable) Filter(f IterFunc) Enumerable
Filter returns a new Enumerable containing only the elements for which the given function returns `true`
func (Enumerable) Find ¶
func (e Enumerable) Find(f IterFunc) (int, AnyValue)
Find calls `f` for each item in the slice until `f` returns `true`. If an item is found, it returns the index of that item and the item itself. If none are found, it returns `NotFound, nil`.
func (Enumerable) First ¶
func (e Enumerable) First(n int) Enumerable
First returns a new Enumerable containing only the first `n` elements
func (Enumerable) Flatten ¶
func (e Enumerable) Flatten() Enumerable
Flatten returns a new slice with each value of the slice concatenated
func (Enumerable) GenericMap ¶
func (e Enumerable) GenericMap(f func(AnyValue) AnyValue) Enumerable
GenericMap does the same thing as `map` but requires a slice type of `[]AnyValue` and requires the function to do type assertions as necessary
func (Enumerable) GetSlice ¶
func (e Enumerable) GetSlice(slicePtr interface{})
GetSlice sets `slicePtr` to the stored slice
func (Enumerable) Group ¶
func (e Enumerable) Group(keyFunc IterFunc) AnyValue
func (Enumerable) JoinAsString ¶
func (e Enumerable) JoinAsString(sep string) string
JoinAsString returns a string with each item converted to string and joined with `sep`.
func (Enumerable) JoinAsStringWithFormat ¶
func (e Enumerable) JoinAsStringWithFormat(format, sep string) string
JoinAsStringWithFormat returns a string with each item converted to string using the given format string (see fmt.Printf) and joined with `sep`.
func (Enumerable) Last ¶
func (e Enumerable) Last(n int) Enumerable
Last returns a new Enumerable containing only the last `n` elements
func (Enumerable) Map ¶
func (e Enumerable) Map(f IterFunc) Enumerable
Map iterates over the slice a returns a new Enumerable
func (Enumerable) Max ¶
func (e Enumerable) Max() AnyValue
Max returns the maximum value in the slice
func (Enumerable) Min ¶
func (e Enumerable) Min() AnyValue
Min returns the minimum value in the slice
func (Enumerable) Reduce ¶
func (e Enumerable) Reduce(memo AnyValue, f IterFunc) AnyValue
Reduce iterates over a slice passing the memo value into the function
func (Enumerable) ReduceToFloat64 ¶
func (e Enumerable) ReduceToFloat64(memo float64, f IterFunc) float64
ReduceToFloat64 calls reduce but forces the memo to be a `float64`
func (Enumerable) ReduceToInt ¶
func (e Enumerable) ReduceToInt(memo int, f IterFunc) int
ReduceToInt calls reduce but forces the memo to be an `int`
func (Enumerable) Reverse ¶
func (e Enumerable) Reverse() Enumerable
Reverse reverses the order of the items in the slice
func (Enumerable) Sort ¶
func (e Enumerable) Sort() Enumerable
func (Enumerable) SortBy ¶
func (e Enumerable) SortBy(f IterFunc) Enumerable
SortBy sorts an Enumerable by the return value of function which is given each item in the slice. The function's return value must be a `string` or `int`.
func (Enumerable) SumAsFloat64 ¶
func (e Enumerable) SumAsFloat64() float64
SumAsFloat64 returns the sum of items in the slice as a float64 value
func (Enumerable) SumAsInt ¶
func (e Enumerable) SumAsInt() int
SumAsInt returns the sum of items in the slice as an int. It will panic if the values are float values
func (Enumerable) ToGeneric ¶
func (e Enumerable) ToGeneric() Enumerable
ToGeneric converts the slice to be of type `[]AnyType`
func (Enumerable) Uniq ¶
func (e Enumerable) Uniq() Enumerable
Uniq returns a new slice with duplicates removed