dictionary

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2018 License: Apache-2.0 Imports: 3 Imported by: 23

Documentation

Overview

Package dictionary provides utilities for operating on map-like types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear added in v1.1.0

func Clear(d I)

Clear removes all entries from the dictionary d.

func IsSource added in v1.1.0

func IsSource(o interface{}) []error

IsSource returns nil if v implements the generic interface Source.

Types

type Entry

type Entry struct {
	K, V interface{}
}

Entry holds a key-value pair.

func Entries added in v1.1.0

func Entries(d I) []Entry

Entries returns the full list of entries in the dictionary d.

type I

type I interface {
	// Get returns the value of the entry with the given key.
	Get(key interface{}) (val interface{})
	// Add inserts the key-value pair, replacing any existing entry with the
	// same key.
	Add(key, val interface{})
	// Lookup searches for the value of the entry with the given key.
	Lookup(key interface{}) (val interface{}, found bool)
	// Contains returns true if the dictionary contains an entry with the given
	// key.
	Contains(key interface{}) bool
	// Remove removes the entry with the given key. If no entry with the given
	// key exists then this call is a no-op.
	Remove(key interface{})
	// Len returns the number of entries in the dictionary.
	Len() int
	// Keys returns all the entry keys in the map.
	Keys() []interface{}
	// KeyTy returns the type of all the entry keys.
	KeyTy() reflect.Type
	// ValTy returns the type of all the entry values.
	ValTy() reflect.Type
}

I is the interface for a dictionary.

func From

func From(o interface{}) I

From returns a dictionary wrapping o. o can be a map or a Source, otherwise nil is returned.

type K added in v1.1.0

type K = generic.T1

K represents a generic key type.

type Source added in v1.1.0

type Source interface {
	// Get returns the value of the entry with the given key.
	Get(K) V
	// Add inserts the key-value pair, replacing any existing entry with the
	// same key.
	Add(K, V)
	// Lookup searches for the value of the entry with the given key.
	Lookup(K) (val V, ok bool)
	// Contains returns true if the dictionary contains an entry with the given
	// key.
	Contains(K) bool
	// Remove removes the entry with the given key. If no entry with the given
	// key exists then this call is a no-op.
	Remove(K)
	// Len returns the number of entries in the dictionary.
	Len() int
	// Keys returns all the entry keys in the map.
	Keys() []K
}

Source is a dummy interface used to prototype a generic dictionary type. K and V can be subsituted with a different type.

type V added in v1.1.0

type V = generic.T2

V represents a generic value type.

Jump to

Keyboard shortcuts

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