ds

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection[T comparable] interface {
	// Add an element to this collection.
	Add(element T)
	// AddAll adds all elements from the given slice to this collection.
	AddAll(elements []T)
	// Count returns the size of this collection.
	Count() int
	// IsEmpty returns whether this collection is empty.
	IsEmpty() bool
	// Has returns whether given element is in this collection.
	Has(element T) bool
	// Contains returns whether all elements in `other` are in this collection.
	Contains(other Collection[T]) bool
	// Equals returns whether this and `other` collections have the same size and contain the same elements.
	Equals(other Collection[T]) bool
	// Pop removes and returns an element from this collection.
	Pop() (T, bool)
	// Remove removes an element from this collection, returns whether this collection
	// changed as a result of the call.
	Remove(element T) bool
	// RemoveAll removes the given elements from this collection, returns whether this collection
	// changed as a result of the call.
	RemoveAll(elements []T) bool
	// RemoveIf removes the given element from this collection based on some condition, then returns
	// true if the element was removed. If the given element doesn't exist in this collection or the
	// element was not removed because of the condition func, false will be returned.
	RemoveIf(element T, conditionFn func() bool) bool
	// Clear removes all elements from this collection.
	Clear()
	// Iter returns a channel which could be used in a for range loop. The capacity of the returned
	// channel is the same as the size of the collection at the time Iter is called.
	Iter() <-chan T
	// Items returns all elements of this collection as a slice.
	Items() []T
	// ForEach executes the given doEachFn on every element in this collection. If `doEachFn` returns
	// true, stop execution immediately.
	ForEach(doEachFn func(element T) bool)
	// String returns a string representation of the current state of the collection.
	String() string
}

Collection is a collection of T.

type Map

type Map[K comparable, V any] interface {
	// Set sets a new k-v pair in this map, then returns the previous value associated with
	// key, and whether such value exists.
	Set(key K, value V) (V, bool)
	// SetAll sets all k-v pairs from the given map in this map.
	SetAll(data map[K]V)
	// Get gets a value based on the given key.
	Get(key K) (V, bool)
	// GetAndSetIf gets a value based on the given key and sets a new value based on some condition,
	// returning all inset and outset params in the condition func.
	GetAndSetIf(key K, conditionFn func(currentVal V, found bool) (newVal V, shouldSet bool)) (currentVal V, found bool, newVal V, shouldSet bool)
	// GetElseCreate return the value associated with the given key and true. If the key doesn't
	// exist in this map, create a new value, set it in the map and then return the new value
	// together with false instead.
	GetElseCreate(key K, newValueFn func() V) (V, bool)
	// Count returns size of this map.
	Count() int
	// IsEmpty returns whether this map is empty.
	IsEmpty() bool
	// Has returns whether given key is in this map.
	Has(key K) bool
	// Remove pops a K-V pair from this map, then returns it.
	Remove(key K) (V, bool)
	// RemoveAll removes all given keys from this map, then returns whether this map changed as a
	// result of the call.
	RemoveAll(keys []K) bool
	// RemoveIf removes the given key from this map based on some condition, then returns the value
	// associated with the removed key and true. If the given key doesn't exist in this map or the
	// key was not removed because of the condition func, a zero-value and false will be returned.
	RemoveIf(key K, conditionFn func(currentVal V) bool) (V, bool)
	// Clear removes all k-v pairs from this map.
	Clear()
	// Iter returns a channel which could be used in a for range loop. The capacity of the returned
	// channel is the same as the size of the map at the time Iter() is called.
	Iter() <-chan Tuple[K, V]
	// Items returns all k-v pairs as a slice of core.Tuple.
	Items() []Tuple[K, V]
	// ForEach executes the given doEachFn on every element in this map. If `doEachFn` returns true,
	// stop execution immediately.
	ForEach(doEachFn func(key K, val V) bool)
	// String returns a string representation of the current state of this map.
	String() string
}

Map is a map for K -> V.

type Marshallable added in v1.0.1

type Marshallable interface {
	// MarshalJSON returns the JSON bytes of this map.
	MarshalJSON() ([]byte, error)
	// UnmarshalJSON consumes a slice of JSON bytes to populate this map.
	UnmarshalJSON(b []byte) error
}

Marshallable ...

type Set

type Set[T comparable] interface {
	Collection[T]
	// Difference returns all elements of this set that are not in `other`.
	Difference(other Set[T]) []T
	// SymmetricDifference returns all elements that are in either this set or `other` but not in both.
	SymmetricDifference(other Set[T]) []T
	// Intersect returns all elements that exist in both sets.
	Intersect(other Set[T]) []T
	// Union returns all elements that are in both sets.
	Union(other Set[T]) []T
	// IsProperSubset returns whether all elements in this set are in `other` but they are not equal.
	IsProperSubset(other Set[T]) bool
}

Set is an unordered set of T.

type Tuple

type Tuple[K any, V any] struct {
	Key K
	Val V
}

Tuple represents a k-v pair.

Jump to

Keyboard shortcuts

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