...

Package mapiter

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

Overview ▾

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

type Iterator

Iterator iterates through keys and values of a map

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

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

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

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

type Source

Source represents a map that knows how to create an iterator

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

type Visitor

Visitor represents an object that handles each pair in a map

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

type VisitorFunc

VisitorFunc is a type of Visitor based on a function

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

func (VisitorFunc) Visit

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