fluent

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2020 License: MIT Imports: 1 Imported by: 34

Documentation

Overview

The fluent package offers helper utilities for using NodeAssembler more tersely by providing an interface that handles all errors for you, and allows use of closures for any recursive assembly so that creating trees of data results in indentation for legibility.

Note that the fluent package creates wrapper objects in order to provide the API conveniences that it does, and this comes at some cost to performance. If you're optimizing for performance, using the fluent interfaces may be inadvisable. However, as with any performance questions, benchmark before making decisions; its entirely possible that your performance bottlenecks will be elsewhere and there's no reason to deny yourself syntactic sugar if the costs don't detectably affect the bottom line.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Build added in v0.0.3

func Build(ns ipld.NodeStyle, fn func(NodeAssembler)) (ipld.Node, error)

func MustBuild added in v0.0.3

func MustBuild(ns ipld.NodeStyle, fn func(NodeAssembler)) ipld.Node

func MustBuildList added in v0.0.3

func MustBuildList(ns ipld.NodeStyle, sizeHint int, fn func(ListAssembler)) ipld.Node

func MustBuildMap added in v0.0.3

func MustBuildMap(ns ipld.NodeStyle, sizeHint int, fn func(MapAssembler)) ipld.Node

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 ListAssembler added in v0.0.3

type ListAssembler interface {
	AssembleValue() NodeAssembler

	ValueStyle(idx int) ipld.NodeStyle
}

ListAssembler is the same as the interface in the core package, except: instead of returning errors, any error will cause panic (and you can collect these with `fluent.Recover`); and all recursive operations take a function as a parameter, within which you will receive another {Map,List,}NodeAssembler.

type MapAssembler added in v0.0.3

type MapAssembler interface {
	AssembleKey() NodeAssembler
	AssembleValue() NodeAssembler

	AssembleEntry(k string) NodeAssembler

	KeyStyle() ipld.NodeStyle
	ValueStyle(k string) ipld.NodeStyle
}

MapAssembler is the same as the interface in the core package, except: instead of returning errors, any error will cause panic (and you can collect these with `fluent.Recover`); and all recursive operations take a function as a parameter, within which you will receive another {Map,List,}NodeAssembler.

type NodeAssembler added in v0.0.3

type NodeAssembler interface {
	CreateMap(sizeHint int, fn func(MapAssembler))
	CreateList(sizeHint int, fn func(ListAssembler))
	AssignNull()
	AssignBool(bool)
	AssignInt(int)
	AssignFloat(float64)
	AssignString(string)
	AssignBytes([]byte)
	AssignLink(ipld.Link)
	AssignNode(ipld.Node)

	Style() ipld.NodeStyle
}

NodeAssembler is the same as the interface in the core package, except: instead of returning errors, any error will cause panic (and you can collect these with `fluent.Recover`); and all recursive operations take a function as a parameter, within which you will receive another {Map,List,}NodeAssembler.

func WrapAssembler added in v0.0.3

func WrapAssembler(na ipld.NodeAssembler) NodeAssembler

Jump to

Keyboard shortcuts

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