Bag

package
v0.0.0-...-a4d351a Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface interface {
	Add(item interface{}) Interface
	Remove(item interface{}) Interface
	Count(item interface{}) int
	Has(item interface{}) bool
	Len() int
	DistinctLen() int
	IsEmpty() bool
	Each(fn func(item interface{}, count int) Result.Interface) Result.Interface
	ToArray() Array.Interface
	DistinctArray() Array.Interface
	Sum(other Interface) Interface
	Union(other Interface) Interface
	Intersection(other Interface) Interface
	Difference(other Interface) Interface
	Equal(other Interface) bool
	IsNull() bool
}

Interface is the public contract of a Bag composite — a multiset (a "counted collection" / Counter): a collection of items each carrying a multiplicity. It rounds out the go-composites collection family next to Set (unique), OrderedSet (insertion-ordered) and SortedSet (sorted), sharing the Each/ToArray grammar of Array. Items are arbitrary comparable values (a Bag is backed by a Go map, so each item must be comparable, exactly like a Dictionary key). Membership tests return a plain bool, fallible iteration returns a Result, and every method honours the Null-Object invariant (never nil).

func New

func New(items ...interface{}) Interface

New creates a Bag seeded with the given items, counting duplicates — so New(1, 1, 2) holds 1 with a count of 2 and 2 with a count of 1. Items must be comparable, since the Bag is backed by a Go map.

func Null

func Null() Interface

Null returns the Null-Object Bag.

Jump to

Keyboard shortcuts

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