package mapiter

import "github.com/lestrrat-go/iter/mapiter"

Index

Functions

func AsMap

func AsMap(ctx context.Context, s interface{}, v interface{}) error

AsMap returns the values obtained from the source as a map

func Walk

func Walk(ctx context.Context, s Source, v Visitor) error

Walk walks through each element in the map

Types

type Iterator

type Iterator interface {
	Next(context.Context) bool
	Pair() *Pair
}

Iterator iterates through keys and values of a map

func Iterate

func Iterate(ctx context.Context, m interface{}) (Iterator, error)

Iterate creates an iterator from arbitrary map types. This is not the most efficient tool, but it's the quickest way to create an iterator for maps. Also, note that you cannot make any assumptions on the order of pairs being returned.

func New

func New(ch chan *Pair) Iterator

type Pair

type Pair struct {
	Key   interface{}
	Value interface{}
}

Pair represents a single pair of key and value from a map

type Source

type Source interface {
	Iterate(context.Context) Iterator
}

Source represents a map that knows how to create an iterator

type Visitor

type Visitor interface {
	Visit(interface{}, interface{}) error
}

Visitor represents an object that handles each pair in a map

type VisitorFunc

type VisitorFunc func(interface{}, interface{}) error

VisitorFunc is a type of Visitor based on a function

func (VisitorFunc) Visit

func (fn VisitorFunc) Visit(s interface{}, v interface{}) error

Source Files

mapiter.go

Version
v1.0.2 (latest)
Published
Mar 29, 2022
Platform
linux/amd64
Imports
4 packages
Last checked
3 weeks ago

Tools for package owners.