yit

package module
v0.0.0-...-9ba8df1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: MIT Imports: 2 Imported by: 23

README

go-yit - YAML Iterator

GoDoc

Introduction

This library compliments go-yaml v3 by adding functional style methods for iterating over YAML documents.

Usage

Import the package

import "github.com/dprotaso/go-yit"

Query your YAML document

package main

import (
	"fmt"
	"log"

	"github.com/dprotaso/go-yit"
	"gopkg.in/yaml.v3"
)

var data = `
a: b
c: d
e: f
`

func main() {
	var doc yaml.Node
	err := yaml.Unmarshal([]byte(data), &doc)

	if err != nil {
		log.Fatalf("error: %v", err)
	}

	it := yit.FromNode(&doc).
		RecurseNodes().
		Filter(yit.WithKind(yaml.MappingNode)).
		MapKeys()

	for node, ok := it(); ok; node, ok = it() {
		fmt.Println(node.Value)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	All = func(node *yaml.Node) bool {
		return true
	}

	None = func(node *yaml.Node) bool {
		return false
	}

	StringValue = Intersect(
		WithKind(yaml.ScalarNode),
		WithShortTag("!!str"),
	)
)

Functions

This section is empty.

Types

type Iterator

type Iterator func() (*yaml.Node, bool)

func FromIterators

func FromIterators(its ...Iterator) Iterator

func FromNode

func FromNode(node *yaml.Node) Iterator

func FromNodes

func FromNodes(nodes ...*yaml.Node) Iterator

func (Iterator) AllMatch

func (next Iterator) AllMatch(p Predicate) bool

func (Iterator) AnyMatch

func (next Iterator) AnyMatch(p Predicate) bool

func (Iterator) Filter

func (next Iterator) Filter(p Predicate) Iterator

func (Iterator) Iterate

func (next Iterator) Iterate(op func(Iterator) Iterator) Iterator

func (Iterator) MapKeys

func (next Iterator) MapKeys() Iterator

func (Iterator) MapValues

func (next Iterator) MapValues() Iterator

func (Iterator) RecurseNodes

func (next Iterator) RecurseNodes() Iterator

func (Iterator) ToArray

func (next Iterator) ToArray() (result []*yaml.Node)

func (Iterator) Values

func (next Iterator) Values() Iterator

func (Iterator) ValuesForMap

func (next Iterator) ValuesForMap(keyPredicate, valuePredicate Predicate) Iterator

type Predicate

type Predicate func(*yaml.Node) bool

func Intersect

func Intersect(ps ...Predicate) Predicate

func Negate

func Negate(p Predicate) Predicate

func Union

func Union(ps ...Predicate) Predicate

func WithKind

func WithKind(kind yaml.Kind) Predicate

func WithMapKey

func WithMapKey(key string) Predicate

func WithMapKeyValue

func WithMapKeyValue(keyPredicate, valuePredicate Predicate) Predicate

func WithMapValue

func WithMapValue(value string) Predicate

func WithPrefix

func WithPrefix(prefix string) Predicate

func WithShortTag

func WithShortTag(tag string) Predicate

func WithStringValue

func WithStringValue(value string) Predicate

func WithSuffix

func WithSuffix(suffix string) Predicate

func WithValue

func WithValue(value string) Predicate

Jump to

Keyboard shortcuts

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