Documentation ¶
Index ¶
- func CamelCase(str string) (string, error)
- func CamelCaseWithInit(str string, upperCase InitCamelCase) (string, error)
- func Capitalize(str string) string
- func Chunk[E any](items []E, size int) [][]E
- func Compact[E any](items []E) []E
- func Concat[E any](items []E, newItems []E) []E
- func ConcatSlices[E any](slices ...[]E) []E
- func Difference[E any](items []E, itemsToCompare []E) []E
- func DifferenceBy[E any](items []E, itemsToCompare []E, iteratee Iteratee[E, E]) []E
- func DifferenceWith[E any](items []E, itemsToCompare []E, comparison Comparison[E]) []E
- func Drop[E any](items []E, count int) []E
- func DropRight[E any](items []E, count int) []E
- func DropWhile[E any](items []E, predicate Predicate[E]) []E
- func EndsWith(str string, target string) bool
- func EndsWithFrom(str string, target string, position int) bool
- func Escape(str string) string
- func EscapeRegExp(str string) string
- func Fill[E any](items []E, fillValue E)
- func FillInRange[E any](items []E, value E, start int, end int)
- func Filter[E any](slice []E, predicate Predicate[E]) []E
- func FindIndex[E any](items []E, predicate Predicate[E]) (int, bool)
- func FindIndexWith[E any](items []E, element E, comparison Comparison[E]) (index int, ok bool)
- func FindLastIndex[E any](items []E, predicate Predicate[E]) (int, bool)
- func FindLastIndexWith[E any](items []E, element E, comparison Comparison[E]) (int, bool)
- func First[E any](items []E) *E
- func FromPairs[K comparable, V any](pairs []KeyValuePair[K, V]) map[K]V
- func FromPairsAny(pairs [][]any) map[any]any
- func Head[E any](items []E) *E
- func IndexOf[E any](items []E, element E) (int, bool)
- func Initial[E any](slice []E) []E
- func Intersection[E any](items1 []E, items2 []E) (intersectedItems []E)
- func IntersectionBy[E, T any](items1 []E, items2 []E, iteratee Iteratee[E, T]) (intersectedItems []E)
- func IntersectionWith[E any](items1 []E, items2 []E, comparison Comparison[E]) (intersectedItems []E)
- func Join[E any](items []E, separator string) string
- func Last[E any](items []E) (exists bool, lastItem E)
- func LastIndexOf[E any](items []E, element E) (int, bool)
- func LowerFirst(str string) string
- func Map[E, V any](slice []E, iteratee func(E) V) []V
- func Nth[E any](items []E, n int) (exists bool, item E)
- func Pad(str string, length int) string
- func PadLeft(str string, length int) string
- func PadLeftWith(str string, length int, padChars string) string
- func PadRight(str string, length int) string
- func PadRightWith(str string, length int, padChars string) string
- func PadWith(str string, length int, padChars string) string
- func Pull[E comparable](items *[]E, values ...E) []E
- func PullAll[E comparable](items *[]E, values []E) []E
- func PullAllWith[E any](items *[]E, values []E, comparison Comparison[E]) []E
- func PullAt[E any](items *[]E, indices ...int) (pulled []E)
- func Remove[E any](items *[]E, predicate Predicate[E]) (removed []E)
- func Repeat(str string, count int) string
- func Replace(source string, target string, newStr string) string
- func ReplaceRegx(source string, pattern string, newStr string) (string, error)
- func Reverse[E any](items []E) []E
- func Slice[E any](items []E, start int, end int) []E
- func Split(str string, separator string) []string
- func SplitWithCountLimit(str string, separator string, n int) []string
- func StartsWith(str string, target string) bool
- func StartsWithFrom(str string, target string, position int) bool
- func Tail[E any](items []E) (result []E)
- func Take[E any](items []E, n int) (results []E)
- func TakeRight[E any](items []E, n int) []E
- func TakeRightWhile[E any](items []E, predicate Predicate[E]) []E
- func TakeWhile[E any](items []E, predicate Predicate[E]) []E
- func Ternary(satisfy bool, truthyValue interface{}, falsyValue interface{}) interface{}
- func ToLower(str string) string
- func ToUpper(str string) string
- func Trim(str string) string
- func TrimEnd(str string) string
- func TrimEndWith(str string, trimChars string) string
- func TrimStart(str string) string
- func TrimStartWith(str string, trimChars string) string
- func TrimWith(str string, trimChars string) string
- func Unescape(str string) string
- func Union[E comparable](slices ...[]E) []E
- func UnionBy[I any, O comparable](iteratee Iteratee[I, O], slices ...[]I) []I
- func UnionWith[E any](comparison Comparison[E], slices ...[]E) []E
- func Uniq[E comparable](items []E) []E
- func UniqBy[I any, O comparable](items []I, iteratee Iteratee[I, O]) []I
- func UniqWith[E any](items []E, comparison Comparison[E]) []E
- func UpperFirst(str string) string
- func Without[E comparable](items []E, values ...E) []E
- func Xor[E comparable](items ...[]E) []E
- func Zip[E any](slices ...[]E) [][]E
- func ZipWith[E any, V any](iteratee Iteratee[[]E, V], slices ...[]E) []V
- type Comparison
- type InitCamelCase
- type Iteratee
- type KeyValuePair
- type Number
- type Predicate
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CamelCaseWithInit ¶
func CamelCaseWithInit(str string, upperCase InitCamelCase) (string, error)
Converts string to camel case. First char is lower case by default.
func Capitalize ¶
Converts the first character of string to upper case and the remaining to lower case.
func Chunk ¶
Creates an array of elements split into groups the length of size. If array can't be split evenly, the final chunk will be the remaining elements.
Example ¶
items := []string{"a", "b", "c", "d"} chunked := Chunk(items, 3) fmt.Println(chunked)
Output: [[a b c] [d]]
func Compact ¶
func Compact[E any](items []E) []E
Creates an array with all falsy values removed. The values false, 0, "", nil are falsy.
Example ¶
items := []interface{}{"a", "b", false, 0, 1, nil, ""} compacted := Compact(items) fmt.Println(compacted...)
Output: a b 1
func Concat ¶
func Concat[E any](items []E, newItems []E) []E
Creates a new array concatenating array with any additional arrays and/or values.
Example ¶
items := []string{"a", "b", "c", "d"} result := Concat(items, []string{"e", "f"}) fmt.Println(result)
Output: [a b c d e f]
func ConcatSlices ¶
func ConcatSlices[E any](slices ...[]E) []E
Creates a new array concatenating array with any additional DashSlices.
func Difference ¶
func Difference[E any](items []E, itemsToCompare []E) []E
Creates an array of array values not included in the other given arrays using SameValueZero for equality comparisons. The order and references of result values are determined by the first array.
Example ¶
items1 := []string{"a", "b", "c", "d"} items2 := []string{"a", "c", "e", "f"} result := Difference(items1, items2) fmt.Println(result)
Output: [b d]
func DifferenceBy ¶
This method is like _.difference except that it accepts iteratee which is invoked for each element of array and values to generate the criterion by which they're compared. The order and references of result values are determined by the first array. The iteratee is invoked with one argument: (value).
Example ¶
items1 := []float64{1.2, 2.4, 5.9} items2 := []float64{1.3, 3.4, 5.1} result := DifferenceBy(items1, items2, func(el float64) float64 { return math.Floor(el) }) fmt.Println(result)
Output: [2.4]
func DifferenceWith ¶
func DifferenceWith[E any](items []E, itemsToCompare []E, comparison Comparison[E]) []E
This method is like _.difference except that it accepts comparator which is invoked to compare elements of array to values. The order and references of result values are determined by the first array. The comparator is invoked with two arguments: (arrVal, othVal).
Example ¶
items1 := []float64{1.2, 2.4, 5.9} items2 := []float64{1.3, 3.4, 5.1} result := DifferenceWith(items1, items2, func(el1 float64, el2 float64) bool { if el1 == 1.2 && el2 == 1.3 { return true } else if el1 == 2.4 && el2 == 3.4 { return true } else { return false } }) fmt.Println(result)
Output: [5.9]
func Drop ¶
Creates a slice of array with n elements dropped from the beginning.
Example ¶
items := []string{"a", "b", "c", "d"} result := Drop(items, 1) fmt.Println(result)
Output: [b c d]
func DropRight ¶
Creates a slice of array with n elements dropped from the end.
Example ¶
items := []string{"a", "b", "c", "d"} result := DropRight(items, 1) fmt.Println(result)
Output: [a b c]
func DropWhile ¶
Creates a slice of array excluding elements dropped from the beginning. Elements are dropped until predicate returns falsy. The predicate is invoked with two arguments: (value, index).
Example ¶
items := []string{"a", "b", "c", "d"} result := DropWhile(items, func(el string) bool { return el == "a" || el == "b" }) fmt.Println(result)
Output: [c d]
func EndsWithFrom ¶
Checks if string ends with the given target string with the position to search up to.
func Escape ¶
Converts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.
func EscapeRegExp ¶
Escapes the RegExp special characters "^", "$", "", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string.
func Fill ¶
func Fill[E any](items []E, fillValue E)
Fills elements of array with value.
Example ¶
items := []string{"a", "b", "c", "d"} Fill(items, "z") fmt.Println(items)
Output: [z z z z]
func FillInRange ¶
Fills elements of array with value from start up to, but not including end.
Example ¶
items := make([]string, 4) FillInRange(items, "z", 0, len(items)) fmt.Println(items)
Output: [z z z z]
func FindIndex ¶
This method is like Find except that it returns the index of the first element predicate returns truthy for instead of the element itself.
Example ¶
items := []string{"a", "b", "c", "d"} result, ok := FindIndex(items, func(el string) bool { return el == "c" }) fmt.Println(result, ok)
Output: 2 true
func FindIndexWith ¶
func FindIndexWith[E any](items []E, element E, comparison Comparison[E]) (index int, ok bool)
Same to IndexOf. The difference is that, this method provides a comparison function to compare programmatically.
Example ¶
items := []float64{2.3, 3.4, 4.5, 5.6} comparison := func(a float64, b float64) bool { return math.Floor(a) == math.Floor(b) } result, ok := FindIndexWith(items, 4.1, comparison) fmt.Println(result, ok)
Output: 2 true
func FindLastIndex ¶
This method is like Find except that it returns the index of the first element predicate returns truthy for instead of the element itself.
Example ¶
items := []string{"a", "b", "b", "d"} result, ok := FindLastIndex(items, func(el string) bool { return el == "b" }) fmt.Println(result, ok)
Output: 1 true
func FindLastIndexWith ¶
func FindLastIndexWith[E any](items []E, element E, comparison Comparison[E]) (int, bool)
This method is like FindIndex except that it iterates over elements of collection from right to left.
Example ¶
items := []string{"a", "b", "b", "d"} result, ok := FindIndex(items, func(el string) bool { return el == "b" }) fmt.Println(result, ok)
Output: 1 true
func FromPairs ¶
func FromPairs[K comparable, V any](pairs []KeyValuePair[K, V]) map[K]V
This method returns an object composed from key-value pairs.
func FromPairsAny ¶
This method returns an object composed from key-value pairs.
func IndexOf ¶
This method is like _.find except that it returns the index of the first element predicate returns truthy for instead of the element itself.
Example ¶
items := []string{"a", "b", "c", "d"} result1, ok := IndexOf(items, "1") fmt.Println(ok, result1) result2, ok := IndexOf(items, "c") fmt.Println(ok, result2)
Output: false -1 true 2
func Intersection ¶
func Intersection[E any](items1 []E, items2 []E) (intersectedItems []E)
Creates an array of unique values that are included in all given arrays using SameValueZero for equality comparisons. The order and references of result values are determined by the first array.
func IntersectionBy ¶
func IntersectionBy[E, T any](items1 []E, items2 []E, iteratee Iteratee[E, T]) (intersectedItems []E)
This method is like Intersection except that it accepts iteratee which is invoked for each element of each arrays to generate the criterion by which they're compared. The order and references of result values are determined by the first array. The iteratee is invoked with one argument: (value).
func IntersectionWith ¶
func IntersectionWith[E any](items1 []E, items2 []E, comparison Comparison[E]) (intersectedItems []E)
This method is like _.intersection except that it accepts comparator which is invoked to compare elements of arrays. The order and references of result values are determined by the first array. The comparator is invoked with two arguments: (arrVal, othVal).
func LastIndexOf ¶
This method is like IndexOf except that it iterates over elements of array from right to left.
Example ¶
items := []string{"a", "b", "c", "b", "d"} result1, ok := LastIndexOf(items, "1") fmt.Println(ok, result1) result2, ok := LastIndexOf(items, "b") fmt.Println(ok, result2)
Output: false -1 true 3
func LowerFirst ¶
func Nth ¶
Gets the element at index n of array. If n is negative, the nth element from the end is returned.
func Pad ¶
Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.
func PadLeftWith ¶
Pads string on the left sides if it's shorter than length.
func PadRightWith ¶
Pads string on the right sides if it's shorter than length.
func PadWith ¶
Pads string on the left and right sides if it's shorter than length. Padding characters are truncated if they can't be evenly divided by length.
func Pull ¶
func Pull[E comparable](items *[]E, values ...E) []E
Removes all given values from array using SameValueZero for equality comparisons.
func PullAll ¶
func PullAll[E comparable](items *[]E, values []E) []E
This method is like Pull except that it accepts an array of values to remove.
func PullAllWith ¶
func PullAllWith[E any](items *[]E, values []E, comparison Comparison[E]) []E
This method is like PullAll except that it accepts comparator which is invoked to compare elements of array to values. The comparator is invoked with two arguments: (arrVal, othVal).
func PullAt ¶
Removes elements from array corresponding to indexes and returns an array of removed elements.
func Remove ¶
Removes all elements from array that predicate returns truthy for and returns an array of the removed elements. The predicate is invoked with two arguments: (value, index).
func ReplaceRegx ¶
Replaces matches for pattern in string with replacement.
func Reverse ¶
func Reverse[E any](items []E) []E
Reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.
func SplitWithCountLimit ¶
Splits string by separator and return limit count items.
func StartsWith ¶
Checks if string starts with the given target string.
func StartsWithFrom ¶
Checks if string starts with the given target string from a specific position.
func TakeRightWhile ¶
Creates a slice of array with elements taken from the end. Elements are taken until predicate returns falsy. The predicate is invoked with one argument: (value).
func TakeWhile ¶
Creates a slice of array with elements taken from the beginning. Elements are taken until predicate returns falsy. The predicate is invoked with one argument: (value).
func Ternary ¶
func Ternary(satisfy bool, truthyValue interface{}, falsyValue interface{}) interface{}
func TrimEndWith ¶
Removes tailing whitespace or specified characters from string.
func TrimStartWith ¶
Removes leading whitespace or specified characters from string.
func Unescape ¶
The inverse of Escape func; this method converts the HTML entities &, <, >, ", and ' in string to their corresponding characters.
func Union ¶
func Union[E comparable](slices ...[]E) []E
Creates an array of unique values, in order, from all given arrays using SameValueZero for equality comparisons.
func UnionBy ¶
func UnionBy[I any, O comparable](iteratee Iteratee[I, O], slices ...[]I) []I
This method is like Uniq except that it accepts iteratee which is invoked for each element in array to generate the criterion by which uniqueness is computed. The order of result values is determined by the order they occur in the array. The iteratee is invoked with one argument: (value).
func UnionWith ¶
func UnionWith[E any](comparison Comparison[E], slices ...[]E) []E
This method is like Uniq except that it accepts comparator which is invoked to compare elements of array. The order of result values is determined by the order they occur in the array. The comparator is invoked with two arguments: (arrVal, othVal).
func Uniq ¶
func Uniq[E comparable](items []E) []E
Creates a duplicate-free version of an array, using SameValueZero for equality comparisons, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array.
func UniqBy ¶
func UniqBy[I any, O comparable](items []I, iteratee Iteratee[I, O]) []I
This method is like Union except that it accepts iteratee which is invoked for each element of each arrays to generate the criterion by which uniqueness is computed. Result values are chosen from the first array in which the value occurs. The iteratee is invoked with one argument: (value).
func UniqWith ¶
func UniqWith[E any](items []E, comparison Comparison[E]) []E
This method is like Uniq except that it accepts comparator which is invoked to compare elements of array. The order of result values is determined by the order they occur in the array. The comparator is invoked with two arguments: (arrVal, othVal).
func UpperFirst ¶
Converts the first character of string to upper case.
func Without ¶
func Without[E comparable](items []E, values ...E) []E
Creates an array excluding all given values using SameValueZero for equality comparisons.
func Xor ¶
func Xor[E comparable](items ...[]E) []E
Creates an array of unique values that is the symmetric difference of the given arrays. The order of result values is determined by the order they occur in the arrays.
Types ¶
type Comparison ¶
type InitCamelCase ¶
type InitCamelCase bool
type KeyValuePair ¶
type KeyValuePair[K comparable, V any] struct { // contains filtered or unexported fields }