fluent

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2020 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllKeyStrings

func AllKeyStrings(n Node) []string

AllKeyStrings is a shorthand to iterate a map node and collect all the keys (and convert them to strings), returning them in a slice.

func Recover

func Recover(fn func()) (err error)

Recover invokes a function within a panic-recovering context, and returns any raised fluent.Error values; any other values are re-panicked.

This can be useful for writing large blocks of code using fluent nodes, and handling any errors at once at the end.

Types

type Error

type Error struct {
	Err error
}

func (Error) Error

func (e Error) Error() string

type ListBuilder

type ListBuilder interface {
	AppendAll([]ipld.Node)
	Append(v ipld.Node)
	Set(idx int, v ipld.Node)
}

type ListBuildingClosure

type ListBuildingClosure func(lb ListBuilder, vnb NodeBuilder)

ListBuildingClosure is the signiture of a function which builds a Node of kind list.

The ListBuilder parameter is used to accumulate the new Node for the duration of the function; and when the function returns, that builder will be invoked. (In other words, there's no need to call `Build` within the closure itself -- and correspondingly, note the lack of return value.)

Additional NodeBuilder handles are provided for building the values. These are used when handling typed Node implementations, since in that case they may contain behavior related to the type contracts. (For untyped nodes, this is degenerate: the 'vnb' builder is not distinct from the parent builder driving this closure.)

type ListIterator

type ListIterator interface {
	Next() (idx int, value Node)
	Done() bool
}

type MapBuilder

type MapBuilder interface {
	Insert(k, v ipld.Node)
	Delete(k ipld.Node)
}

type MapBuildingClosure

type MapBuildingClosure func(mb MapBuilder, knb NodeBuilder, vnb NodeBuilder)

MapBuildingClosure is the signiture of a function which builds a Node of kind map.

The MapBuilder parameter is used to accumulate the new Node for the duration of the function; and when the function returns, that builder will be invoked. (In other words, there's no need to call `Build` within the closure itself -- and correspondingly, note the lack of return value.)

Additional NodeBuilder handles are provided for building keys and values. These are used when handling typed Node implementations, since in that case they may contain behavior related to the type contracts. (For untyped nodes, this is degenerate: these builders are not distinct from the parent builder driving this closure.)

REVIEW : whether 'knb' is needed. Not sure, and there are other pending discussions on this. (It's mostly a concern about having a place to do validation on construction; but it's possible we can solve this without additional Nodes and Builders by making that validation the responsibility of the inside of the mb.Insert method; but will this compose well, and will it convey the appropriate times to do the validations correctly? Is 'knb' relevant even if that last question is 'no'? If a concern is to avoid double-validations, that argues for `mb.Insert(Node, Node)` over `mb.Insert(string, Node)`, but if avoiding double-validations, that means we already have a Node and don't need 'knb' to get one. ... Design!)

type MapIterator

type MapIterator interface {
	Next() (key Node, value Node)
	Done() bool
}

type Node

type Node interface {
	ReprKind() ipld.ReprKind
	LookupString(path string) Node
	Lookup(key Node) Node
	LookupIndex(idx int) Node
	MapIterator() MapIterator
	ListIterator() ListIterator
	Length() int
	IsNull() bool
	AsBool() bool
	AsInt() int
	AsFloat() float64
	AsString() string
	AsBytes() []byte
	AsLink() ipld.Link
	GetError() error
}

fluent.Node is an interface with all the same methods names as ipld.Node, but all of the methods return only the thing itself, and not error values -- which makes chaining calls easier.

The very first error value encountered will be stored, and can be viewed later. After an error is encountered, all subsequent lookup methods will silently return the same error-storing node. Any of the terminal scalar-returning methods will panic if an error is stored. (The fluent.Recover function can be used to nicely gather these panics.)

func WrapNode

func WrapNode(n ipld.Node) Node

type NodeBuilder

type NodeBuilder interface {
	CreateMap(MapBuildingClosure) ipld.Node
	AmendMap(MapBuildingClosure) ipld.Node
	CreateList(ListBuildingClosure) ipld.Node
	AmendList(ListBuildingClosure) ipld.Node
	CreateNull() ipld.Node
	CreateBool(bool) ipld.Node
	CreateInt(int) ipld.Node
	CreateFloat(float64) ipld.Node
	CreateString(string) ipld.Node
	CreateBytes([]byte) ipld.Node
	CreateLink(ipld.Link) ipld.Node
}

func WrapNodeBuilder

func WrapNodeBuilder(nb ipld.NodeBuilder) NodeBuilder

Jump to

Keyboard shortcuts

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