Documentation ¶
Overview ¶
Package collection provide a collection type that can set generics type for any type or any pointer
Index ¶
- type Collection
- func (c *Collection[T]) Each(f func(i T)) *Collection[T]
- func (c *Collection[T]) Filter(f func(i T) bool) *Collection[T]
- func (c *Collection[T]) Len() int
- func (c *Collection[T]) Map(f func(i T) T) *Collection[T]
- func (c *Collection[T]) Merge(other *Collection[T])
- func (c *Collection[T]) Peek(i int) T
- func (c *Collection[T]) Sort(f func(i, j T) bool) *Collection[T]
- func (c *Collection[T]) Value() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collection ¶
type Collection[T item] struct {
// contains filtered or unexported fields
}
Collection can set generics for any type or any pointer you must choose using pointer or not
func New ¶
func New[T item](d []T) *Collection[T]
New can be used to create a new collection you can use collection.New([]string{"a", "b", "c"}) or collection.New([]int{1, 2, 3}) or collection.New([]Book{{Name: "a", Price: 2}, {Name: "b", Price: 3}, {Name: "c", Price: 4}}) or collection.New([]*Book{{Name: "a", Price: 2}, {Name: "b", Price: 3}, {Name: "c", Price: 4}})
func (*Collection[T]) Each ¶
func (c *Collection[T]) Each(f func(i T)) *Collection[T]
Each can be used to iterate over the collection
func (*Collection[T]) Filter ¶
func (c *Collection[T]) Filter(f func(i T) bool) *Collection[T]
Filter can be used to filter the collection only when the function returns true
func (*Collection[T]) Map ¶
func (c *Collection[T]) Map(f func(i T) T) *Collection[T]
Map can be used to map the collection
func (*Collection[T]) Merge ¶
func (c *Collection[T]) Merge(other *Collection[T])
Merge can be used to merge two collections
func (*Collection[T]) Peek ¶
func (c *Collection[T]) Peek(i int) T
Peek can be used to get the value
func (*Collection[T]) Sort ¶
func (c *Collection[T]) Sort(f func(i, j T) bool) *Collection[T]
Sort sorts the elements in the Collection using the provided function.
func (*Collection[T]) Value ¶
func (c *Collection[T]) Value() []T
Value can be used to get the value slice