Godash
This is lodash in golang version. A modern Golang utility library delivering modularity, performance & extras.
Install / Use
/learn @ginkgoch/GodashREADME
Lodash in Golang Version V2
This is lodash in golang version v2. A modern Golang utility library delivering modularity, performance & extras. Compare to v1, all APIs are refactored with generic types support. API Reference.
Install & Import
go get -u "github.com/ginkgoch/godash/v2"
import "github.com/ginkgoch/godash/v2"
Usage
func CamelCase
func CamelCase(str string) (string, error)
Converts string to camel case. First char is lower case.
func CamelCaseWithInit
func CamelCaseWithInit(str string, upperCase InitCamelCase) (string, error)
Converts string to camel case. First char is lower case by default.
func Capitalize
func Capitalize(str string) string
Converts the first character of string to upper case and the remaining to lower case.
func Chunk
func Chunk[E any](items []E, size int) [][]E
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.
func Compact
func Compact[E any](items []E) []E
Creates an array with all falsy values removed. The values false, 0, "", nil are falsy.
func Concat
func Concat[E any](items []E, newItems []E) []E
Creates a new array concatenating array with any additional arrays and/or values.
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.
func DifferenceBy
func DifferenceBy[E any](items []E, itemsToCompare []E, iteratee Iteratee[E, E]) []E
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).
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).
func Drop
func Drop[E any](items []E, count int) []E
Creates a slice of array with n elements dropped from the beginning.
func DropRight
func DropRight[E any](items []E, count int) []E
Creates a slice of array with n elements dropped from the end.
func DropWhile
func DropWhile[E any](items []E, predicate Predicate[E]) []E
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).
func EndsWith
func EndsWith(str string, target string) bool
Checks if string ends with the given target string.
func EndsWithFrom
func EndsWithFrom(str string, target string, position int) bool
Checks if string ends with the given target string with the position to search up to.
func Escape
func Escape(str string) string
Converts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.
func EscapeRegExp
func EscapeRegExp(str string) string
Escapes the RegExp special characters "^", "$", "", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string.
func Fill
func Fill[E any](items []E, fillValue E)
Fills elements of array with value.
func FillInRange
func FillInRange[E any](items []E, value E, start int, end int)
Fills elements of array with value from start up to, but not including end.
func Filter
func Filter[E any](slice []E, predicate Predicate[E]) []E
func FindIndex
func FindIndex[E any](items []E, predicate Predicate[E]) (int, bool)
This method is like Find except that it returns the index of the first element predicate returns truthy for instead of the element itself.
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.
func FindLastIndex
func FindLastIndex[E any](items []E, predicate Predicate[E]) (int, bool)
This method is like Find except that it returns the index of the first element predicate returns truthy for instead of the element itself.
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.
func First
func First[E any](items []E) *E
Gets the first element of array.
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
func FromPairsAny(pairs [][]any) map[any]any
This method returns an object composed from key-value pairs.
func Head
func Head[E any](items []E) *E
Gets the first element of slice.
func IndexOf
func IndexOf[E any](items []E, element E) (int, bool)
This method is like _.find except that it returns the index of the first element predicate returns truthy for instead of the element itself.
func Initial
func Initial[E any](slice []E) []E
Gets all but the last element of array.
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 Join
func Join[E any](items []E, separator string) string
Converts all elements in array into a string separated by separator.
func Last
func Last[E any](items []E) (exists bool, lastItem E)
Gets the last element of array.
func LastIndexOf
func LastIndexOf[E any](items []E, element E) (int, bool)
This method is like IndexOf except that it iterates over elements of array from right to left.
func LowerFirst
func LowerFirst(str string) string
func Map
func Map[E, V any](slice []E, iteratee func(E) V) []V
func Nth
func Nth[E any](items []E, n int) (exists bool, item E)
Gets the element at index n of array. If n is negative, the nth element from the end is returned.
func Pad
func Pad(str string, length int) string
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 PadLeft
func PadLeft(str string, length int) string
Pads string on the left sides if it's shorter than length.
func PadLeftWith
func PadLeftWith(str string, length int, padChars string) string
Pads string on the left sides if it's shorter than length.
func PadRight
func PadRight(str string, length int) string
Pads string on the right sides if it's shorter than length.
func PadRightWith
func PadRightWith(str string, length int, padChars string) string
Pads string on the right sides if it's shorter than length.
func PadWith
func PadWith(str string, length int, padChars string) string
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 t
