Documentation ¶
Index ¶
- Variables
- func Avg[V Number](c Collection[V]) V
- func Max[V Number](c Collection[V]) V
- func Min[V Number](c Collection[V]) V
- func Reduce[T CollectionElement](l *List[T], callback listReduceFunction[T], initialValue T) T
- func Sum[V Number](c Collection[V]) V
- type Collection
- type CollectionElement
- type CollectionType
- type Equatable
- type GenericType
- type List
- func (l *List[T]) Add(item T)
- func (l *List[T]) Contains(item T) bool
- func (l *List[T]) CountOf(item T) (count int)
- func (l *List[T]) Distinct() *List[T]
- func (l *List[T]) Extend(l2 *List[T])
- func (l *List[T]) Get(index int) (item T, err error)
- func (l *List[T]) IndexOf(item T) int
- func (l *List[T]) RemoveAll(item T) error
- func (l *List[T]) RemoveDuplicates()
- func (l *List[T]) RemoveFirst(item T) error
- func (l *List[T]) Size() int
- func (l *List[T]) String() string
- func (l *List[T]) ToArray() []T
- func (_ List[T]) Type() CollectionType
- func (l *List[T]) Where(f func(T) bool) *List[T]
- type Number
- type Set
- func (s *Set[T]) Add(item T)
- func (s *Set[T]) Clear()
- func (s *Set[T]) Contains(item T) bool
- func (s *Set[T]) Difference(s2 *Set[T]) *Set[T]
- func (s *Set[T]) Extend(s2 *Set[T])
- func (s *Set[T]) Intersection(s2 *Set[T]) *Set[T]
- func (s *Set[T]) Remove(item T) error
- func (s *Set[T]) Size() int
- func (s *Set[T]) String() string
- func (s *Set[T]) ToArray() []T
- func (_ Set[T]) Type() CollectionType
- func (s *Set[T]) Union(s2 *Set[T]) *Set[T]
Constants ¶
This section is empty.
Variables ¶
var ( ErrIndexOutOfRange = errors.New("linq: index out of range") ErrItemNotFound = errors.New("linq: item not found") )
Functions ¶
func Avg ¶ added in v1.0.1
func Avg[V Number](c Collection[V]) V
Returns the average of all elements present in the given collection. This method supports only numerical types.
func Max ¶ added in v1.0.1
func Max[V Number](c Collection[V]) V
Returns maximum element present in the given collection. This method supports only numerical types.
func Min ¶ added in v1.0.1
func Min[V Number](c Collection[V]) V
Returns minimum element present in the given collection. This method supports only numerical types.
func Reduce ¶ added in v1.0.1
func Reduce[T CollectionElement](l *List[T], callback listReduceFunction[T], initialValue T) T
Use Reduce to reduce the given list elements to a single element of same type T based on a callback function.
func Sum ¶ added in v1.0.1
func Sum[V Number](c Collection[V]) V
Returns the sum of all elements present in the given collection. This method supports only numerical types.
Types ¶
type Collection ¶
type Collection[T CollectionElement] interface { // Returns the type of the given collection. Type() CollectionType // Returns the size of the given collection. Size() int // Returns the description of the given collection. String() string }
Generic interface that all collections must implement.
type CollectionElement ¶
type CollectionElement interface { Equatable }
A Generic interface that must be implemented by collection elements. By default, all primitive types and structs containing primitive types implement this interface.
type CollectionType ¶
type CollectionType int
Typed constant that helps in determining the collection type.
const ( TypeList CollectionType = 0 TypeSet CollectionType = 1 TypeHashmap CollectionType = 2 )
type Equatable ¶
type Equatable interface { comparable }
Interface with comparable constraint (== & != operator supportable).
type GenericType ¶
type List ¶ added in v1.0.1
type List[T CollectionElement] struct { // contains filtered or unexported fields }
Collection that stores homogenous elements in a fixed order.
func Map ¶ added in v1.0.1
func Map[T CollectionElement, E CollectionElement](l *List[T], callback listMapFunction[T, E]) *List[E]
Use Map method to transform a list of a given type to another type.
func NewList ¶ added in v1.0.1
func NewList[T CollectionElement](capacity int) *List[T]
Factory method to create an empty list with predefined capacity.
func RepeatingList ¶ added in v1.0.1
func RepeatingList[T CollectionElement](element T, times int) *List[T]
Factory method to create a list with repeating values
func ToList ¶ added in v1.0.1
func ToList[T CollectionElement](array []T) *List[T]
Factory method to create a list from an array.
func (*List[T]) CountOf ¶ added in v1.0.1
Returns number of occurences of given element in the list.
func (*List[T]) Get ¶ added in v1.0.1
Returns list element for a valid index. Returns error for an invalid index.
func (*List[T]) IndexOf ¶ added in v1.0.1
Returns the index of the first occurence of the element. If the element is not present in the list, it returns -1.
func (*List[T]) RemoveAll ¶ added in v1.0.1
Removes all occurences of the given element from the list. Returns an error if the element is not present in the list.
func (*List[T]) RemoveDuplicates ¶ added in v1.0.1
func (l *List[T]) RemoveDuplicates()
Removes duplicates of elements in the list.
func (*List[T]) RemoveFirst ¶ added in v1.0.1
Removes first occurence of the given element from the list. Returns an error if the element is not present in the list.
func (*List[T]) ToArray ¶ added in v1.0.1
func (l *List[T]) ToArray() []T
Returns an slice containing elements of the list.
func (List[T]) Type ¶ added in v1.0.1
func (_ List[T]) Type() CollectionType
type Set ¶ added in v1.0.1
type Set[T CollectionElement] struct { // contains filtered or unexported fields }
Collection that stores a set of homogenous elements.
func NewSet ¶ added in v1.0.1
func NewSet[T CollectionElement]() *Set[T]
Factory method to create an empty set with predefined capacity.
func ToSet ¶ added in v1.0.1
func ToSet[T CollectionElement](array []T) *Set[T]
Factory method to create a set from an array.
func (*Set[T]) Difference ¶ added in v1.0.1
Returns a new set instance containing elements that exists in the first set, but not in the second.
func (*Set[T]) Intersection ¶ added in v1.0.1
Returns a new set instance containing the elements that exists in both sets.
func (*Set[T]) Remove ¶ added in v1.0.1
Removes occurence of the given element from the set. Returns an error if the element is not present in the set.
func (*Set[T]) ToArray ¶ added in v1.0.1
func (s *Set[T]) ToArray() []T
Returns an slice containing elements of the set.
func (Set[T]) Type ¶ added in v1.0.1
func (_ Set[T]) Type() CollectionType