node

package
v0.0.0-...-8a9fb8e Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package node define action, and decision nodes.

You can also create your own node if the struct respect the Node interface. A Node use a Context during computation as input data and output data.

NOTE: you will also find a "go-cmp" comparator for Node.

Index

Constants

This section is empty.

Variables

View Source
var (
	// NodeComparator is a google/go-cmp comparator of Node
	NodeComparator = cmp.Comparer(func(x, y Node) bool {
		return x == y
	})
)

Functions

This section is empty.

Types

type ActionNode

type ActionNode struct {
	// contains filtered or unexported fields
}

ActionNode is a type of Node who compute a function to realize some actions based on Context.

func NewAction

func NewAction(name string, actionFunc func(*Context) error) (*ActionNode, error)

NewAction create a ActionNode based on a name and a function to realize the needed action.

func (*ActionNode) Compute

Compute run the action function and decide which compute state to return.

func (*ActionNode) DecideCapability

func (n *ActionNode) DecideCapability() bool

DecideCapability is desactived due to the fact that an action don't take a decision.

func (ActionNode) String

func (n ActionNode) String() string

type Context

type Context struct {
	Data map[string]interface{}
}

Context hold data during an Computation

func NewContext

func NewContext(data map[string]interface{}) *Context

NewContext generate a new Context with data

func NewContextWithoutData

func NewContextWithoutData() *Context

NewContextWithoutData generate a new empty Context

func (*Context) Delete

func (c *Context) Delete(key string)

Delete remove a value in the context by its key

func (Context) Equal

func (c Context) Equal(o Context) bool

Equal validate the two Context are equals

func (*Context) HaveKey

func (c *Context) HaveKey(key string) bool

HaveKey validate that a key is in the context

func (*Context) Read

func (c *Context) Read(key string) (interface{}, bool)

Read get a value in the context by its key

func (*Context) Store

func (c *Context) Store(key string, value interface{})

Store add a key and its value to the context

type DecisionNode

type DecisionNode struct {
	// contains filtered or unexported fields
}

DecisionNode is a type of Node who compute a function to take a decision based on Context.

func NewDecision

func NewDecision(name string, decisionFunc func(*Context) (bool, error)) (*DecisionNode, error)

NewDecision create a DecisionNode based on a name and a function to take the needed decision.

func (*DecisionNode) Compute

Compute run the decision function and decide which compute state to return.

func (*DecisionNode) DecideCapability

func (n *DecisionNode) DecideCapability() bool

DecideCapability is actived due to the fact that an decision is taked during compute.

func (DecisionNode) String

func (n DecisionNode) String() string

type Node

type Node interface {
	// Compute a node based on a context
	Compute(c *Context) computestate.ComputeState
	// DecideCapability tell if the Node can decide.
	// This impact the compute state by adding a branch to the state.
	DecideCapability() bool
}

Node define

Jump to

Keyboard shortcuts

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