-- import "github.com/ginkgoch/godash"
This is lodash golang version. A modern Golang utility library delivering modularity, performance & extras.
- func CamelCase
- func CamelCaseWithInit
- func Capitalize
- func CountBy
- func EndsWith
- func EndsWithFrom
- func Escape
- func EscapeRegExp
- func Every
- func Fill
- func FillInRange
- func Find
- func FindFrom
- func FindIndex
- func FindIndexWith
- func FindLast
- func FindLastFrom
- func FindLastIndex
- func FindLastIndexWith
- func First
- func FromPairs
- func GroupBy
- func Head
- func Identity
- func IdentityFloat
- func IdentityInt
- func IdentityString
- func Includes
- func IndexOf
- func Join
- func Last
- func LastIndexOf
- func LowerFirst
- func Nth
- func Pad
- func PadLeft
- func PadLeftWith
- func PadRight
- func PadRightWith
- func PadWith
- func Reduce
- func ReduceRight
- func ReduceRightWithInitial
- func ReduceWithInitial
- func Repeat
- func Replace
- func ReplaceRegx
- func Sample
- func Size
- func Some
- func Split
- func SplitWithCountLimit
- func StartsWith
- func StartsWithFrom
- func Ternary
- func ToLower
- func ToUpper
- func Trim
- func TrimEnd
- func TrimEndWith
- func TrimStart
- func TrimStartWith
- func TrimWith
- func Unescape
- func UpperFirst
- type Action
- type Comparison
- type DashSlice
- func Chunk
- func Compact
- func Concat
- func ConcatSlices
- func Difference
- func DifferenceBy
- func DifferenceWith
- func Drop
- func DropRight
- func DropWhile
- func Each
- func EachRight
- func Filter
- func FlatMap
- func FlatMapDeep
- func FlatMapDepth
- func Flatten
- func FlattenDeep
- func FlattenDepth
- func ForEach
- func ForEachRight
- func Initial
- func Intersection
- func IntersectionBy
- func IntersectionWith
- func Map
- func NewDashSlice
- func NewDashSliceFromIntArray
- func Pull
- func PullAll
- func PullAllWith
- func PullAt
- func Reject
- func Remove
- func Reverse
- func SampleSize
- func Shuffle
- func Slice
- func SortByFloat
- func SortByInt
- func SortByString
- func Tail
- func Take
- func TakeRight
- func TakeRightWhile
- func TakeWhile
- func Union
- func UnionBy
- func UnionWith
- func Uniq
- func UniqBy
- func UniqWith
- func Without
- func Xor
- func Zip
- func ZipWith
- func (DashSlice) Map
- type InitCamelCase
- type Iteratee
- type IterateeToFloat
- type IterateeToInt
- type IterateeToString
- type Predicate
- type Reducer
func CamelCase(str string) (string, error)
Converts string to camel case. First char is lower case.
func CamelCaseWithInit(str string, upperCase InitCamelCase) (string, error)
Converts string to camel case. First char is lower case by default.
func Capitalize(str string) string
Converts the first character of string to upper case and the remaining to lower case.
func CountBy(items DashSlice, iteratee Iteratee) map[interface{}]int
Creates an object composed of keys generated from the results of running each element of collection thru iteratee. The corresponding value of each key is the number of times the key was returned by iteratee. The iteratee is invoked with one argument: (value).
func EndsWith(str string, target string) bool
Checks if string ends with the given target string.
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(str string) string
Converts the characters "&", "<", ">", '"', and "'" in string to their corresponding HTML entities.
func EscapeRegExp(str string) string
Escapes the RegExp special characters "^", "$", "", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in string.
func Every(items DashSlice, predicate Predicate) bool
Checks if predicate returns truthy for all elements of collection. Iteration is stopped once predicate returns falsy. The predicate is invoked with one argument: (value).
func Fill(items DashSlice, fillValue interface{})
Fills elements of array with value.
func FillInRange(items DashSlice, value interface{}, start int, end int)
Fills elements of array with value from start up to, but not including end.
func Find(items DashSlice, predicate Predicate) (interface{}, bool)
Iterates over elements of collection, returning the first element predicate returns truthy for. The predicate is invoked with one argument: (value).
func FindFrom(items DashSlice, predicate Predicate, start int) (interface{}, bool)
Iterates over elements of collection from start index, returning the first element predicate returns truthy for. The predicate is invoked with one argument: (value).
func FindIndex(items DashSlice, predicate Predicate) (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(items DashSlice, element interface{}, comparison Comparison) (int, bool)
Same to IndexOf. The difference is that, this method provides a comparison function to compare programmatically.
func FindLast(items DashSlice, predicate Predicate) (interface{}, bool)
This method is like Find except that it iterates over elements of collection from right to left.
func FindLastFrom(items DashSlice, predicate Predicate, start int) (interface{}, bool)
This method is like FindFrom except that it iterates over elements of collection from right to left.
func FindLastIndex(items DashSlice, predicate Predicate) (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(items DashSlice, element interface{}, comparison Comparison) (int, bool)
This method is like FindIndex except that it iterates over elements of collection from right to left.
func First(items DashSlice) interface{}
Gets the first element of array.
func FromPairs(pairs []DashSlice) map[interface{}]interface{}
This method returns an object composed from key-value pairs.
func GroupBy(items DashSlice, iteratee Iteratee) map[interface{}]DashSlice
Creates an object composed of keys generated from the results of running each element of collection thru iteratee. The order of grouped values is determined by the order they occur in collection. The corresponding value of each key is an array of elements responsible for generating the key. The iteratee is invoked with one argument: (value).
func Head(items DashSlice) interface{}
Gets the first element of slice.
func Identity(i interface{}) interface{}
func IdentityFloati interface{}) float
func IdentityInt(i interface{}) int
func IdentityString(i interface{}) string
func Includes(items DashSlice, value interface{}) bool
Checks if value is in collection. If collection is a string, it's checked for a substring of value, otherwise SameValueZero is used for equality comparisons. If fromIndex is negative, it's used as the offset from the end of collection.
func IndexOf(items DashSlice, element interface{}) (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 Join(items DashSlice, separator string) string
Converts all elements in array into a string separated by separator.
func Last(items DashSlice) interface{}
Gets the last element of array.
func LastIndexOf(items DashSlice, element interface{}) (int, bool)
This method is like IndexOf except that it iterates over elements of array from right to left.
func LowerFirst(str string) string
func Nth(items DashSlice, n int) interface{}
Gets the element at index n of array. If n is negative, the nth element from the end is returned.
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(str string, length int) string
Pads string on the left sides if it's shorter than length.
func PadLeftWith(str string, length int, padChars string) string
Pads string on the left sides if it's shorter than length.
func PadRight(str string, length int) string
Pads string on the right sides if it's shorter than length.
func PadRightWith(str string, length int, padChars string) string
Pads string on the right sides if it's shorter than length.
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 Reduce(items DashSlice, reducer Reducer) interface{}
Reduces collection to a value which is the accumulated result of running each element in collection thru iteratee, where each successive invocation is supplied the return value of the previous. If accumulator is not given, the first element of collection is used as the initial value. The reducer is invoked with two arguments: (accumulator, value).
func ReduceRight(items DashSlice, reducer Reducer) interface{}
This method is like Reduce except that it iterates over elements of collection from right to left.
func ReduceRightWithInitial(items DashSlice, reducer Reducer, initial interface{}) interface{}
This method is like ReduceWithInitial except that it iterates over elements of collection from right to left.
func ReduceWithInitial(items DashSlice, reducer Reducer, initial interface{}) interface{}
Reduces collection to a value which is the accumulated result of running each element in collection thru iteratee, where each successive invocation is supplied the return value of the previous. If accumulator is not given, the first element of collection is used as the initial value. The reducer is invoked with two arguments: (accumulator, value).
func Repeat(str string, count int) string
Repeats the given string n times.
func Replace(source string, target string, newStr string) string
Replaces string with replacement.
func ReplaceRegx(source string, pattern string, newStr string) (string, error)
Replaces matches for pattern in string with replacement.
func Sample(items DashSlice) interface{}
Gets a random element from collection.
func Size(items DashSlice) int
Gets the size of collection.
func Some(items DashSlice, predicate Predicate) bool
Checks if predicate returns truthy for any element of collection. Iteration is stopped once predicate returns truthy. The predicate is invoked with one argument: (value).
func Split(str string, separator string) []string
Splits string by separator.
func SplitWithCountLimit(str string, separator string, n int) []string
Splits string by separator and return limit count items.
func StartsWith(str string, target string) bool
Checks if string starts with the given target string.
func StartsWithFrom(str string, target string, position int) bool
Checks if string starts with the given target string from a specific position.
func Ternary(satisfy bool, truthyValue interface{}, falsyValue interface{}) interface{}
func ToLower(str string) string
Converts string, as a whole, to lower case.
func ToUpper(str string) string
Converts string, as a whole, to upper case
func Trim(str string) string
Removes leading and trailing whitespace from string.
func TrimEnd(str string) string
Removes tailing whitespace from string.
func TrimEndWith(str string, trimChars string) string
Removes tailing whitespace or specified characters from string.
func TrimStart(str string) string
Removes leading whitespace from string.
func TrimStartWith(str string, trimChars string) string
Removes leading whitespace or specified characters from string.
func TrimWith(str string, trimChars string) string
Removes leading and trailing whitespace or specified characters from string.
func Unescape(str string) string
The inverse of Escape func; this method converts the HTML entities &, <, >, ", and &#in string to their corresponding characters.
func UpperFirst(str string) string
Converts the first character of string to upper case.
type Action func(interface{}, int)
type Comparison func(interface{}, interface{}) bool
type DashSlice []interface{}
func Chunk(items DashSlice, size int) []DashSlice
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(items DashSlice) DashSlice
Creates an array with all falsy values removed. The values false, "", nil are falsy.
func Concat(items DashSlice, newItems ...interface{}) DashSlice
Creates a new array concatenating array with any additional arrays and/or values.
func ConcatSlices(slices ...DashSlice) DashSlice
Creates a new array concatenating array with any additional DashSlices.
func Difference(items DashSlice, itemsToCompare ...interface{}) DashSlice
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(items DashSlice, itemsToCompare DashSlice, iteratee Iteratee) DashSlice
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(items DashSlice, itemsToCompare DashSlice,
comparison Comparison) DashSlice
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(items DashSlice, count int) DashSlice
Creates a slice of array with n elements dropped from the beginning.
func DropRight(items DashSlice, count int) DashSlice
Creates a slice of array with n elements dropped from the end.
func DropWhile(items DashSlice, predicate Predicate) DashSlice
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 Each(items DashSlice, action Action) DashSlice
Iterates over elements of collection and invokes iteratee for each element. The iteratee is invoked with three arguments: (value, index|key, collection). Iteratee functions may exit iteration early by explicitly returning false.
func EachRight(items DashSlice, action Action) DashSlice
This method is like ForEach except that it iterates over elements of collection from right to left.
func Filter(items DashSlice, predicate Predicate) DashSlice
Iterates over elements of collection, returning an array of all elements predicate returns truthy for. The predicate is invoked with one argument: (value).
func FlatMap(items DashSlice, iteratee Iteratee) DashSlice
Creates a flattened array of values by running each element in collection thru iteratee and flattening the mapped results. The iteratee is invoked with one argument: (value).
func FlatMapDeep(items DashSlice, iteratee Iteratee) DashSlice
This method is like FlatMap except that it recursively flattens the mapped results.
func FlatMapDepth(items DashSlice, iteratee Iteratee, depth int) DashSlice
This method is like FlatMap except that it recursively flattens the mapped results up to depth times.
func Flatten(items DashSlice) DashSlice
Flattens array a single level deep.
func FlattenDeep(items DashSlice) DashSlice
Recursively flattens array.
func FlattenDepth(items DashSlice, depth int) DashSlice
Recursively flatten array up to depth times.
func ForEach(items DashSlice, action Action) DashSlice
Iterates over elements of collection and invokes iteratee for each element. The iteratee is invoked with three arguments: (value, index|key, collection). Iteratee functions may exit iteration early by explicitly returning false.
func ForEachRight(items DashSlice, action Action) DashSlice
This method is like ForEach except that it iterates over elements of collection from right to left.
func Initial(items DashSlice) DashSlice
Gets all but the last element of array.
func Intersection(itemsDashSlice, itemsDashSlice) DashSlice
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(itemsDashSlice, itemsDashSlice, iteratee Iteratee) DashSlice
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(itemsDashSlice, itemsDashSlice, comparison Comparison) DashSlice
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 Map(items DashSlice, iteratee Iteratee) DashSlice
Creates an array of values by running each element in collection thru iteratee. The iteratee is invoked with one argument: (value).
func NewDashSlice(items ...interface{}) DashSlice
func NewDashSliceFromIntArray(items ...int) DashSlice
func Pull(items *DashSlice, values ...interface{}) DashSlice
Removes all given values from array using SameValueZero for equality comparisons.
func PullAll(items *DashSlice, values DashSlice) DashSlice
This method is like Pull except that it accepts an array of values to remove.
func PullAllWith(items *DashSlice, values DashSlice, comparison Comparison) DashSlice
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(items *DashSlice, indices ...int) DashSlice
Removes elements from array corresponding to indexes and returns an array of removed elements.
func Reject(items DashSlice, predicate Predicate) DashSlice
The opposite of Filter; this method returns the elements of collection that predicate does not return truthy for.
func Remove(items *DashSlice, predicate Predicate) DashSlice
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 Reverse(items DashSlice) DashSlice
Reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.
func SampleSize(items DashSlice, n int) DashSlice
Gets n random elements at unique keys from collection up to the size of collection.
func Shuffle(items DashSlice) DashSlice
Creates an array of shuffled values.
func Slice(items DashSlice, start int, end int) DashSlice
Creates a slice of array from start up to, but not including, end.
func SortByFloatitems DashSlice, iteratee IterateeToFloat) DashSlice
Creates an array of elements, sorted in ascending order by the results of running each element in a collection thru each iteratee. This method performs a stable sort, that is, it preserves the original sort order of equal elements. The iteratee is invoked with one argument: (value).
func SortByInt(items DashSlice, iteratee IterateeToInt) DashSlice
Creates an array of elements, sorted in ascending order by the results of running each element in a collection thru each iteratee. This method performs a stable sort, that is, it preserves the original sort order of equal elements. The iteratee is invoked with one argument: (value).
func SortByString(items DashSlice, iteratee IterateeToString) DashSlice
Creates an array of elements, sorted in ascending order by the results of running each element in a collection thru each iteratee. This method performs a stable sort, that is, it preserves the original sort order of equal elements. The iteratee is invoked with one argument: (value).
func Tail(items DashSlice) DashSlice
Gets all but the first element of array.
func Take(items DashSlice, n int) DashSlice
Creates a slice of array with n elements taken from the beginning.
func TakeRight(items DashSlice, n int) DashSlice
Creates a slice of array with n elements taken from the end.
func TakeRightWhile(items DashSlice, predicate Predicate) DashSlice
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(items DashSlice, predicate Predicate) DashSlice
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 Union(slices ...DashSlice) DashSlice
Creates an array of unique values, in order, from all given arrays using SameValueZero for equality comparisons.
func UnionBy(iteratee Iteratee, slices ...DashSlice) DashSlice
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(comparison Comparison, slices ...DashSlice) DashSlice
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(items DashSlice) DashSlice
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(items DashSlice, iteratee Iteratee) DashSlice
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(items DashSlice, comparison Comparison) DashSlice
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 Without(items DashSlice, values ...interface{}) DashSlice
Creates an array excluding all given values using SameValueZero for equality comparisons.
func Xor(items ...DashSlice) DashSlice
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.
func Zip(slices ...DashSlice) []DashSlice
Creates an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on.
func ZipWith(iteratee func([]interface{}) interface{}, slices ...DashSlice) DashSlice
This method is like Zip except that it accepts iteratee to specify how grouped values should be combined. The iteratee is invoked with the elements of each group: (...group).
func (ds DashSlice) Map(iteratee func(interface{}) interface{}) DashSlice
type InitCamelCase bool
type Iteratee func(interface{}) interface{}
type IterateeToFloat func(interface{}) float
type IterateeToInt func(interface{}) int
type IterateeToString func(interface{}) string
type Predicate func(interface{}) bool
type Reducer func(interface{}, interface{}) interface{}