Documentation ¶
Overview ¶
Package ugo is a toolbox, inspired by underscore.js This package provide some of the underscore most used functions
Usage:
package main import ( u "github.com/alxrm/ugo" ) func main() { strArr := u.Seq{ "nineteen", "three", "eleven", "five", "seventy", "six", "seven", "one" } lengths := u.Map(strArr, func(cur, _, _ u.Object) u.Object { return len(cur.(string)) }) fmt.Println(lengths) // Output: [8 5 6 4 7 3 5 3] }
Index ¶
- func All(seq Seq, cb Predicate) bool
- func Any(seq Seq, cb Predicate) bool
- func Contains(seq Seq, target Object, isSorted bool, cb Comparator) bool
- func CountBy(seq Seq, cb Callback) (result map[string]int)
- func Each(seq Seq, cb Action)
- func EqualsNotStrict(seqLeft, seqRight Seq, cb Comparator) bool
- func EqualsStrict(seqLeft, seqRight Seq, cb Comparator) bool
- func Every(seq Seq, cb Predicate) bool
- func FindIndex(seq Seq, cb Predicate) int
- func FindLastIndex(seq Seq, cb Predicate) int
- func ForEach(seq Seq, cb Action)
- func GroupBy(seq Seq, cb Callback) map[Object]Seq
- func Includes(seq Seq, target Object, isSorted bool, cb Comparator) bool
- func IndexOf(seq Seq, target Object, isSorted bool, cb Comparator) int
- func IsEmpty(seq Seq) bool
- func IsSlice(target Object) bool
- func LastIndexOf(seq Seq, target Object, cb Comparator) int
- func Random(min, max float64) int
- func Some(seq Seq, cb Predicate) bool
- type Action
- type Callback
- type ChainWrapper
- func (wrapper *ChainWrapper) All(cb Predicate) *ChainWrapper
- func (wrapper *ChainWrapper) Any(cb Predicate) *ChainWrapper
- func (wrapper *ChainWrapper) Collect(cb Callback) *ChainWrapper
- func (wrapper *ChainWrapper) Concat(next Seq) *ChainWrapper
- func (wrapper *ChainWrapper) Contains(target Object, isSorted bool, cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) CountBy(cb Callback) *ChainWrapper
- func (wrapper *ChainWrapper) Detect(cb Predicate) *ChainWrapper
- func (wrapper *ChainWrapper) Difference(other Seq, cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) Each(cb Action) *ChainWrapper
- func (wrapper *ChainWrapper) EqualsNotStrict(other Seq, cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) EqualsStrict(other Seq, cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) Every(cb Predicate) *ChainWrapper
- func (wrapper *ChainWrapper) Filter(cb Predicate) *ChainWrapper
- func (wrapper *ChainWrapper) Find(cb Predicate) *ChainWrapper
- func (wrapper *ChainWrapper) FindIndex(cb Predicate) *ChainWrapper
- func (wrapper *ChainWrapper) FindLast(cb Predicate) *ChainWrapper
- func (wrapper *ChainWrapper) FindLastIndex(cb Predicate) *ChainWrapper
- func (wrapper *ChainWrapper) FoldL(cb Collector, initial Object) *ChainWrapper
- func (wrapper *ChainWrapper) FoldR(cb Collector, initial Object) *ChainWrapper
- func (wrapper *ChainWrapper) ForEach(cb Action) *ChainWrapper
- func (wrapper *ChainWrapper) GroupBy(cb Callback) *ChainWrapper
- func (wrapper *ChainWrapper) Includes(target Object, isSorted bool, cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) IndexOf(target Object, isSorted bool, cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) Inject(cb Collector, initial Object) *ChainWrapper
- func (wrapper *ChainWrapper) Insert(tg Object, pos int) *ChainWrapper
- func (wrapper *ChainWrapper) Intersection(other Seq, cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) LastIndexOf(target Object, cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) Map(cb Callback) *ChainWrapper
- func (wrapper *ChainWrapper) Max(cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) Min(cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) Reduce(cb Collector, initial Object) *ChainWrapper
- func (wrapper *ChainWrapper) ReduceRight(cb Collector, initial Object) *ChainWrapper
- func (wrapper *ChainWrapper) Reject(cb Predicate) *ChainWrapper
- func (wrapper *ChainWrapper) Remove(pos int) *ChainWrapper
- func (wrapper *ChainWrapper) Reverse() *ChainWrapper
- func (wrapper *ChainWrapper) Select(cb Predicate) *ChainWrapper
- func (wrapper *ChainWrapper) Shuffle() *ChainWrapper
- func (wrapper *ChainWrapper) Some(cb Predicate) *ChainWrapper
- func (wrapper *ChainWrapper) SortBy(cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) Union(other Seq, cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) Uniq(cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) Unique(cb Comparator) *ChainWrapper
- func (wrapper *ChainWrapper) Value() Object
- func (wrapper *ChainWrapper) Without(nonGrata Object, cb Comparator) *ChainWrapper
- type Collector
- type Comparator
- type Object
- func Detect(seq Seq, cb Predicate) Object
- func Find(seq Seq, cb Predicate) Object
- func FindLast(seq Seq, cb Predicate) Object
- func FoldL(seq Seq, cb Collector, initial Object) Object
- func FoldR(seq Seq, cb Collector, initial Object) Object
- func Inject(seq Seq, cb Collector, initial Object) Object
- func Max(seq Seq, cb Comparator) Object
- func Min(seq Seq, cb Comparator) Object
- func Reduce(seq Seq, cb Collector, initial Object) Object
- func ReduceRight(seq Seq, cb Collector, initial Object) Object
- type Predicate
- type Seq
- func Collect(seq Seq, cb Callback) Seq
- func Concat(seq, next Seq) Seq
- func Difference(seq, other Seq, cb Comparator) Seq
- func Filter(seq Seq, cb Predicate) Seq
- func From(target Object, size int) Seq
- func Insert(seq Seq, target Object, position int) Seq
- func Intersection(seq, other Seq, cb Comparator) Seq
- func Map(seq Seq, cb Callback) Seq
- func NewSeq(size int) Seq
- func Reject(seq Seq, cb Predicate) Seq
- func Remove(seq Seq, position int) Seq
- func Reverse(seq Seq) Seq
- func ReversedCopy(seq Seq) Seq
- func Select(seq Seq, cb Predicate) Seq
- func Shuffle(seq Seq) Seq
- func ShuffledCopy(seq Seq) Seq
- func SortBy(seq Seq, cb Comparator) Seq
- func Union(seq, other Seq, cb Comparator) Seq
- func Uniq(seq Seq, cb Comparator) Seq
- func Unique(seq Seq, cb Comparator) Seq
- func Without(seq Seq, nonGrata Object, cb Comparator) Seq
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
func Contains(seq Seq, target Object, isSorted bool, cb Comparator) bool
Contains returns true if slice contains element, which equals to passed one(target) NOTE: if slice is sorted, this method can use better search algorithm
func CountBy ¶
CountBy returns map, which values are count of certain kind of values, and keys are names of this kinds
func EqualsNotStrict ¶
func EqualsNotStrict(seqLeft, seqRight Seq, cb Comparator) bool
EqualsNotStrict checks whether both of the given slices are equal, but not strictly, e. g. they the same values, but positions can be different
func EqualsStrict ¶
func EqualsStrict(seqLeft, seqRight Seq, cb Comparator) bool
EqualsStrict checks whether both of the given slices are strictly equal, e. g. they got the same values in the same positions
func FindLastIndex ¶
FindLastIndex returns last found index, which value passed the predicate check
func GroupBy ¶
GroupBy returns map, which keys are results of Callback calculation, and the value is the slice of elements, which gave such result
func Includes ¶
func Includes(seq Seq, target Object, isSorted bool, cb Comparator) bool
Includes is an alias for Contains (see #Contains)
func IndexOf ¶
func IndexOf(seq Seq, target Object, isSorted bool, cb Comparator) int
IndexOf founds index of the first element, which equals to passed one(target) NOTE: if slice is sorted, this method can use better search algorithm
func LastIndexOf ¶
func LastIndexOf(seq Seq, target Object, cb Comparator) int
LastIndexOf founds index of the last element, which equals to passed one(target)
Types ¶
type Action ¶
type Action func(current, currentKey, src Object)
Action is an alias type for function, used to do some action based on given values, which has following args:
* Object current
* int index
* Seq list
type Callback ¶
Callback is an alias type for function, used to get calculated result, which has following args:
* Object current
* int index
* Seq list
* returns Object: modified Seq element
type ChainWrapper ¶
type ChainWrapper struct { Mid Seq // Mid is for middleware calculations Res Object // Res if for resulting data }
ChainWrapper is the special struct, containing resulting and middleware data
func Chain ¶
func Chain(target Seq) *ChainWrapper
Chain method is a start point for chaining behaviour like that: u.Chain(Seq).Map(...).Filter(...).Reduce(...).Value()
func (*ChainWrapper) All ¶
func (wrapper *ChainWrapper) All(cb Predicate) *ChainWrapper
All is a chaining wrapper for #All
func (*ChainWrapper) Any ¶
func (wrapper *ChainWrapper) Any(cb Predicate) *ChainWrapper
Any is a chaining wrapper for #Any
func (*ChainWrapper) Collect ¶
func (wrapper *ChainWrapper) Collect(cb Callback) *ChainWrapper
Collect is a chaining wrapper for #Collect
func (*ChainWrapper) Concat ¶
func (wrapper *ChainWrapper) Concat(next Seq) *ChainWrapper
Concat is a chaining wrapper for #Concat
func (*ChainWrapper) Contains ¶
func (wrapper *ChainWrapper) Contains(target Object, isSorted bool, cb Comparator) *ChainWrapper
Contains is a chaining wrapper for #Contains
func (*ChainWrapper) CountBy ¶
func (wrapper *ChainWrapper) CountBy(cb Callback) *ChainWrapper
CountBy is a chaining wrapper for #CountBy
func (*ChainWrapper) Detect ¶
func (wrapper *ChainWrapper) Detect(cb Predicate) *ChainWrapper
Detect is a chaining wrapper for #Detect
func (*ChainWrapper) Difference ¶
func (wrapper *ChainWrapper) Difference(other Seq, cb Comparator) *ChainWrapper
Difference is a chaining wrapper for #Difference
func (*ChainWrapper) Each ¶
func (wrapper *ChainWrapper) Each(cb Action) *ChainWrapper
Each is a chaining wrapper for #Each
func (*ChainWrapper) EqualsNotStrict ¶
func (wrapper *ChainWrapper) EqualsNotStrict(other Seq, cb Comparator) *ChainWrapper
EqualsNotStrict is a chaining wrapper for #EqualsNotStrict
func (*ChainWrapper) EqualsStrict ¶
func (wrapper *ChainWrapper) EqualsStrict(other Seq, cb Comparator) *ChainWrapper
EqualsStrict is a chaining wrapper for #EqualsStrict
func (*ChainWrapper) Every ¶
func (wrapper *ChainWrapper) Every(cb Predicate) *ChainWrapper
Every is a chaining wrapper for #Every
func (*ChainWrapper) Filter ¶
func (wrapper *ChainWrapper) Filter(cb Predicate) *ChainWrapper
Filter is a chaining wrapper for #Filter
func (*ChainWrapper) Find ¶
func (wrapper *ChainWrapper) Find(cb Predicate) *ChainWrapper
Find is a chaining wrapper for #Find
func (*ChainWrapper) FindIndex ¶
func (wrapper *ChainWrapper) FindIndex(cb Predicate) *ChainWrapper
FindIndex is a chaining wrapper for #FindIndex
func (*ChainWrapper) FindLast ¶
func (wrapper *ChainWrapper) FindLast(cb Predicate) *ChainWrapper
FindLast is a chaining wrapper for #FindLast
func (*ChainWrapper) FindLastIndex ¶
func (wrapper *ChainWrapper) FindLastIndex(cb Predicate) *ChainWrapper
FindLastIndex is a chaining wrapper for #FindLastIndex
func (*ChainWrapper) FoldL ¶
func (wrapper *ChainWrapper) FoldL(cb Collector, initial Object) *ChainWrapper
FoldL is a chaining wrapper for #FoldL
func (*ChainWrapper) FoldR ¶
func (wrapper *ChainWrapper) FoldR(cb Collector, initial Object) *ChainWrapper
FoldR is a chaining wrapper for #FoldR
func (*ChainWrapper) ForEach ¶
func (wrapper *ChainWrapper) ForEach(cb Action) *ChainWrapper
ForEach is a chaining wrapper for #ForEach
func (*ChainWrapper) GroupBy ¶
func (wrapper *ChainWrapper) GroupBy(cb Callback) *ChainWrapper
GroupBy is a chaining wrapper for #GroupBy
func (*ChainWrapper) Includes ¶
func (wrapper *ChainWrapper) Includes(target Object, isSorted bool, cb Comparator) *ChainWrapper
Includes is a chaining wrapper for #Includes
func (*ChainWrapper) IndexOf ¶
func (wrapper *ChainWrapper) IndexOf(target Object, isSorted bool, cb Comparator) *ChainWrapper
IndexOf is a chaining wrapper for #IndexOf
func (*ChainWrapper) Inject ¶
func (wrapper *ChainWrapper) Inject(cb Collector, initial Object) *ChainWrapper
Inject is a chaining wrapper for #Inject
func (*ChainWrapper) Insert ¶
func (wrapper *ChainWrapper) Insert(tg Object, pos int) *ChainWrapper
Insert is a chaining wrapper for #Insert
func (*ChainWrapper) Intersection ¶
func (wrapper *ChainWrapper) Intersection(other Seq, cb Comparator) *ChainWrapper
Intersection is a chaining wrapper for #Intersection
func (*ChainWrapper) LastIndexOf ¶
func (wrapper *ChainWrapper) LastIndexOf(target Object, cb Comparator) *ChainWrapper
LastIndexOf is a chaining wrapper for #LastIndexOf
func (*ChainWrapper) Map ¶
func (wrapper *ChainWrapper) Map(cb Callback) *ChainWrapper
Map is a chaining wrapper for #Map
func (*ChainWrapper) Max ¶
func (wrapper *ChainWrapper) Max(cb Comparator) *ChainWrapper
Max is a chaining wrapper for #Max
func (*ChainWrapper) Min ¶
func (wrapper *ChainWrapper) Min(cb Comparator) *ChainWrapper
Min is a chaining wrapper for #Min
func (*ChainWrapper) Reduce ¶
func (wrapper *ChainWrapper) Reduce(cb Collector, initial Object) *ChainWrapper
Reduce is a chaining wrapper for #Reduce
func (*ChainWrapper) ReduceRight ¶
func (wrapper *ChainWrapper) ReduceRight(cb Collector, initial Object) *ChainWrapper
ReduceRight is a chaining wrapper for #ReduceRight
func (*ChainWrapper) Reject ¶
func (wrapper *ChainWrapper) Reject(cb Predicate) *ChainWrapper
Reject is a chaining wrapper for #Reject
func (*ChainWrapper) Remove ¶
func (wrapper *ChainWrapper) Remove(pos int) *ChainWrapper
Remove is a chaining wrapper for #Remove
func (*ChainWrapper) Reverse ¶
func (wrapper *ChainWrapper) Reverse() *ChainWrapper
Reverse is a chaining wrapper for #Reverse
func (*ChainWrapper) Select ¶
func (wrapper *ChainWrapper) Select(cb Predicate) *ChainWrapper
Select is a chaining wrapper for #Select
func (*ChainWrapper) Shuffle ¶
func (wrapper *ChainWrapper) Shuffle() *ChainWrapper
Shuffle is a chaining wrapper for #Shuffle
func (*ChainWrapper) Some ¶
func (wrapper *ChainWrapper) Some(cb Predicate) *ChainWrapper
Some is a chaining wrapper for #Some
func (*ChainWrapper) SortBy ¶
func (wrapper *ChainWrapper) SortBy(cb Comparator) *ChainWrapper
SortBy is a chaining wrapper for #SortBy
func (*ChainWrapper) Union ¶
func (wrapper *ChainWrapper) Union(other Seq, cb Comparator) *ChainWrapper
Union is a chaining wrapper for #Union
func (*ChainWrapper) Uniq ¶
func (wrapper *ChainWrapper) Uniq(cb Comparator) *ChainWrapper
Uniq is a chaining wrapper for #Uniq
func (*ChainWrapper) Unique ¶
func (wrapper *ChainWrapper) Unique(cb Comparator) *ChainWrapper
Unique is a chaining wrapper for #Unique
func (*ChainWrapper) Value ¶
func (wrapper *ChainWrapper) Value() Object
Value returns result of calculations, you've done through chaining calls
func (*ChainWrapper) Without ¶
func (wrapper *ChainWrapper) Without(nonGrata Object, cb Comparator) *ChainWrapper
Without is a chaining wrapper for #Without
type Collector ¶
Collector is an alias type for function, used in Reduce based methods, which has following args:
* Object memo
* Object current
* int index
* Seq list
* returns Object: memo, modified after some iteration
type Comparator ¶
Comparator is an alias type for function, used to compare one value with another one, which has following args:
* Object left
* Object right
* returns int: -1 for less, 0 for equals, 1 for larger
type Object ¶
type Object interface{}
Object is an alias type for interface{}
func Max ¶
func Max(seq Seq, cb Comparator) Object
Max returns max value from slice, calculated in comparator
func Min ¶
func Min(seq Seq, cb Comparator) Object
Min returns min value from slice, calculated in comparator
type Predicate ¶
Predicate is an alias type for function, used to check value for some condition, which has following args:
* Object current
* int index
* Seq list
* returns bool: true if check has been passed
type Seq ¶
type Seq []interface{}
Seq is an alias type for (generic) interface{} slice e. g. []interface{}
func Difference ¶
func Difference(seq, other Seq, cb Comparator) Seq
Difference returns the values from slice that are not present in the other slice
func From ¶
From returns Seq from given object, filling the resulting Seq via reflection NOTE: You should possibly avoid using this one
func Intersection ¶
func Intersection(seq, other Seq, cb Comparator) Seq
Intersection returns the values that are intersection of two slices Each value in the result is present in each of the arrays.
func SortBy ¶
func SortBy(seq Seq, cb Comparator) Seq
SortBy returns sorted slice, uses very powerful timsort* algorithm *timsort obtained from: https://github.com/psilva261/timsort
func Union ¶
func Union(seq, other Seq, cb Comparator) Seq
Union returns the unique values that are union of two slices each value in the result appears at least once in one of the passed slices
func Uniq ¶
func Uniq(seq Seq, cb Comparator) Seq
Uniq returns slice, which contains only unique elements, calculated by Comparator