collection

package module
v0.0.0-...-8a70ded Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

README

Collections

Go Reference

Iterable generic collections for go v1.23+.

Experimental.

You can use these with go1.22 IF you use GOEXPERIMENT=rangefunc

Example

s := collection.NewSet("1", "a", "b")
for i := range s.Iter() {
    fmt.Println(i)
}

Done so far

  • Concrete Types: Set, OrderedSet
  • Interfaces: Collection
  • Funcs: Union(), Intersection()

To maybe do

Data structures:

  • Queue, Deque
  • LinkedList
  • Map? for concurrent/immutable/sorted variants?

Variants:

  • Ordered*
  • Concurrent*
  • Immutable*
  • Sorted*

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection[E comparable] interface {
	Add(...E)
	Clear()
	Contains(E) bool
	Iter() iter.Seq[E]
	Len() int
	IsEmpty() bool
	Slice() []E
}

type OrderedSet

type OrderedSet[E comparable] struct {
	// contains filtered or unexported fields
}

func NewOrderedSet

func NewOrderedSet[E comparable](vals ...E) *OrderedSet[E]

func (*OrderedSet[E]) Add

func (s *OrderedSet[E]) Add(vals ...E)

func (*OrderedSet[E]) Clear

func (s *OrderedSet[E]) Clear()

func (*OrderedSet[E]) Contains

func (s *OrderedSet[E]) Contains(v E) bool

func (*OrderedSet[E]) IsEmpty

func (s *OrderedSet[E]) IsEmpty() bool

func (*OrderedSet[E]) Iter

func (s *OrderedSet[E]) Iter() iter.Seq[E]

func (*OrderedSet[E]) Len

func (s *OrderedSet[E]) Len() int

func (*OrderedSet[E]) Slice

func (s *OrderedSet[E]) Slice() []E

type Set

type Set[E comparable] struct {
	// contains filtered or unexported fields
}

func Intersection

func Intersection[E comparable](s, s2 Collection[E]) *Set[E]

func NewSet

func NewSet[E comparable](vals ...E) *Set[E]

func Union

func Union[E comparable](s, s2 Collection[E]) *Set[E]

func (*Set[E]) Add

func (s *Set[E]) Add(vals ...E)

func (*Set[E]) Clear

func (s *Set[E]) Clear()

func (*Set[E]) Contains

func (s *Set[E]) Contains(v E) bool

func (*Set[E]) IsEmpty

func (s *Set[E]) IsEmpty() bool

func (*Set[E]) Iter

func (s *Set[E]) Iter() iter.Seq[E]

func (*Set[E]) Len

func (s *Set[E]) Len() int

func (*Set[E]) Slice

func (s *Set[E]) Slice() []E

func (*Set[E]) String

func (s *Set[E]) String() string

Jump to

Keyboard shortcuts

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