collection

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2023 License: MIT Imports: 1 Imported by: 1

Documentation

Index

Constants

View Source
const (
	IterTypeNone = iota
	IterTypeFilter
	IterTypeMap
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator[T any] interface {
	Ranger[T]
	//Slice 会返回一个新的符合条件的Slice
	Slice() *Slice[T]
	//Map 根据输入值映射对应的输出值
	Map(f func(val T) T) Iterator[T]
	//Filter 过滤符合条件的元素
	Filter(f func(val T) bool) Iterator[T]
	//Reduce 类似js的reduce
	Reduce(f func(previousValue any, val T) any, initialValue any) any
}

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewMap

func NewMap[K comparable, V comparable]() *Map[K, V]

func (Map[K, V]) Add

func (m Map[K, V]) Add(k K, v V) (success bool)

func (Map[K, V]) Clear

func (m Map[K, V]) Clear()

func (Map[K, V]) Combine

func (m Map[K, V]) Combine(other Map[K, V]) (success int)

func (Map) Filter

func (di Map) Filter(f func(val T) bool) Iterator[T]

func (Map[K, V]) Get

func (m Map[K, V]) Get(k K, def ...V) (V, bool)

func (Map[K, V]) Keys

func (m Map[K, V]) Keys() *Slice[K]

func (Map) Map

func (di Map) Map(f func(val T) T) Iterator[T]

func (Map[K, V]) Range

func (m Map[K, V]) Range(fn func(p Pairs[K, V]) bool)

func (Map) Reduce

func (di Map) Reduce(f func(previousValue any, val T) any, initialValue any) any

func (Map[K, V]) Remove

func (m Map[K, V]) Remove(k K) V

func (Map) Slice

func (di Map) Slice() *Slice[T]

func (Map[K, V]) Update

func (m Map[K, V]) Update(k K, v V) (old V)

func (Map[K, V]) Values

func (m Map[K, V]) Values() []V

type MapSet

type MapSet[T comparable] map[T]struct{}

func NewMapSet

func NewMapSet[T comparable]() MapSet[T]

func (MapSet[T]) Add

func (s MapSet[T]) Add(member T)

func (MapSet[T]) Clear

func (s MapSet[T]) Clear()

func (MapSet[T]) Combine

func (s MapSet[T]) Combine(other MapSet[T]) (success int)

func (MapSet[T]) IsMember

func (s MapSet[T]) IsMember(member T) (ok bool)

func (MapSet[T]) Len

func (s MapSet[T]) Len() int

func (MapSet[T]) Members

func (s MapSet[T]) Members() *Slice[T]

func (MapSet[T]) Pop

func (s MapSet[T]) Pop() (ret T)

func (MapSet[T]) Rand

func (s MapSet[T]) Rand() (ret T)

func (MapSet[T]) Remove

func (s MapSet[T]) Remove(member T)

type Pairs

type Pairs[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func (*Pairs[K, V]) Key

func (p *Pairs[K, V]) Key() K

func (*Pairs[K, V]) SetKey

func (p *Pairs[K, V]) SetKey(k K)

func (*Pairs[K, V]) SetValue

func (p *Pairs[K, V]) SetValue(v V)

func (*Pairs[K, V]) Value

func (p *Pairs[K, V]) Value() V

type Ranger

type Ranger[T any] interface {
	// Range calls f sequentially for each key and value present in the map.
	// If f returns false, range stops the iteration.
	Range(f func(val T) bool)
}

type Slice

type Slice[T any] struct {
	// contains filtered or unexported fields
}

func NewSlice

func NewSlice[T any](args ...int) *Slice[T]

func WrapSlice

func WrapSlice[T any](s []T) *Slice[T]

func (*Slice[T]) Append

func (s *Slice[T]) Append(ele ...T)

func (*Slice[T]) At

func (s *Slice[T]) At(index int) (ret T, err error)

func (*Slice[T]) Clear

func (s *Slice[T]) Clear()

func (Slice) Filter

func (di Slice) Filter(f func(val T) bool) Iterator[T]

func (*Slice[T]) Find

func (s *Slice[T]) Find(fn func(ele T) bool) bool

func (*Slice[T]) FindIndex

func (s *Slice[T]) FindIndex(fn func(ele T) bool) int

func (*Slice[T]) Insert

func (s *Slice[T]) Insert(index int, ele ...T) error

func (*Slice[T]) Length

func (s *Slice[T]) Length() int

func (Slice) Map

func (di Slice) Map(f func(val T) T) Iterator[T]

func (*Slice[T]) Range

func (s *Slice[T]) Range(fn func(val T) bool)

func (Slice) Reduce

func (di Slice) Reduce(f func(previousValue any, val T) any, initialValue any) any

func (*Slice[T]) Remove

func (s *Slice[T]) Remove(index int) error

func (Slice) Slice

func (di Slice) Slice() *Slice[T]

func (*Slice[T]) Source

func (s *Slice[T]) Source() []T

func (*Slice[T]) Update

func (s *Slice[T]) Update(index int, ele T) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL