rcollections

package
Version: v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2020 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package rcollections contains a (deprecated) interface and implementation for collections Deprecated: use GoDS instead

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StrMap

type StrMap interface {
	// Add adds the given key, value pair to the map.
	// return indicates whether a value was overwritten
	Add(key string, value interface{}) StrMap
	// AddAll creates a new map of the combination of both.
	// For intersections, the value from the other map is chosen
	AddAll(other StrMap) StrMap
	// Contains indicates whether the given key is inside the map
	Contains(needle string) bool
	// ContainsValue indicates whether the given value is inside the map
	ContainsValue(needle interface{}) bool
	// Get retrieves the value at the given key.  Returns a non-nil error If the value is not found
	Get(needle string) (interface{}, error)
	// GetWithDefault retrieves the value at the given key.
	// If the key is found, the associated value is returned
	// Otherwise, the given default value is returned
	GetWithDefault(needle string, deflt interface{}) interface{}
	// Remove removes the given key from the map
	// If the key doesn't exist in the map, it's considered a no-op
	Remove(key string) StrMap
	// RemoveAll removes all the keys from the given keyslice from the map, and returns a new resulting map
	// If the key doesn't exist in the map, it's considered a no-op
	RemoveAll(keys []string) StrMap
	// RemoveIntersections calls Remove for all keys in the other map, and returns a new resulting map
	RemoveIntersections(other StrMap) StrMap
	// Intersection is the resulting map of all keys in both maps.  The value is taken from the other map
	Intersection(other StrMap) StrMap
	// Disjunction is the resulting map of all keys NOT in both maps.
	Disjunction(other StrMap) StrMap
	// ContainsAll indicates whether this map contains all the keys of the other map
	// i.e. is the set of this map's keys a superset of the other map's keys
	// if other is empty, true is returned
	ContainsAll(other StrMap) bool
	// ContainsAny indicates whether this map contains any of the keys of the other map
	// i.e. if ContainsAny returns true, the intersection would be non-empty
	// if other is empty, true is returned
	ContainsAny(other StrMap) bool
	// Len returns the number of elements in the map
	Len() int
	// IsEmpty indicates whether the map is empty. i.e. its Len() is 0
	IsEmpty() bool
	// Equals indicates whether both maps have the same keysets, and each key's value is equal
	Equals(other StrMap) bool
	// ValueFrequency counts the number of times a value occurs in the map
	ValueFrequency(needle interface{}) int
	// Filter applies the given function to all values in the map.
	// The function must receive a key:value keypair and return an indicator whether the element should be retained
	// i.e. if the function returns true, it will appear in the resulting map
	Filter(func(key string, val interface{}) bool) StrMap
	// Map applies the given function to all values in the map.
	// The function must receive a key:value keypair and return the mutated value
	Map(func(key string, val interface{}) interface{}) StrMap
	// Reduce applies the given function to all values in the map.
	// The function must receive a key:value keypair along with an accumulator and return the mutated accumulator
	// Since the accumulator is an interface, the function must handle an uninitialized accumulator and type it appropriately
	Reduce(func(key string, val interface{}, acc interface{}) interface{}) interface{}
	// contains filtered or unexported methods
}

StrMap is an interface for a String-based map

func NewStrMap

func NewStrMap() StrMap

NewStrMap returns an implementation of the StrMap interface

func NewStrMapFrom added in v0.3.1

func NewStrMapFrom(orig map[string]interface{}) StrMap

NewStrMapFrom returns an implementation of the StrMap interface, pre-populated with the given map

Source Files

Jump to

Keyboard shortcuts

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