package coreiter

import "github.com/purpleidea/mgmt/lang/core/iter"

Index

Constants

const (
	// FilterFuncName is the name this function is registered as.
	FilterFuncName = "filter"
)
const (
	// MapFuncName is the name this function is registered as.
	MapFuncName = "map"
)
const (
	// ModuleName is the prefix given to all the functions in this module.
	ModuleName = "iter"
)
const (
	// RangeFuncName is the name this function is registered as.
	RangeFuncName = "range"
)

Types

type FilterFunc

type FilterFunc struct {
	Type *types.Type // this is the type of the elements in our input list
	// contains filtered or unexported fields
}

FilterFunc is the standard filter iterator function that runs a function on each element in a list. That function must return true to keep the element, or false otherwise. The function then returns a list with the subset of kept elements from the input list. This implements the signature: `func(inputs []?1, function func(?1) bool) []?1` instead of the alternate with the two input args swapped, because while the latter is more common with languages that support partial function application, the former variant that we implemented is much more readable when using an inline lambda.

func (*FilterFunc) ArgGen

func (obj *FilterFunc) ArgGen(index int) (string, error)

ArgGen returns the Nth arg name for this function.

func (*FilterFunc) Build

func (obj *FilterFunc) Build(typ *types.Type) (*types.Type, error)

Build is run to turn the polymorphic, undetermined function, into the specific statically typed version. It is usually run after Unify completes, and must be run before Info() and any of the other Func interface methods are used. This function is idempotent, as long as the arg isn't changed between runs.

func (*FilterFunc) Copy

func (obj *FilterFunc) Copy() interfaces.Func

Copy is implemented so that the type value is not lost if we copy this function.

func (*FilterFunc) Info

func (obj *FilterFunc) Info() *interfaces.Info

Info returns some static info about itself. Build must be called before this will return correct data.

func (*FilterFunc) Init

func (obj *FilterFunc) Init(init *interfaces.Init) error

Init runs some startup code for this function.

func (*FilterFunc) Stream

func (obj *FilterFunc) Stream(ctx context.Context) error

Stream returns the changing values that this func has over time.

func (*FilterFunc) String

func (obj *FilterFunc) String() string

String returns a simple name for this function. This is needed so this struct can satisfy the pgraph.Vertex interface.

func (*FilterFunc) Validate

func (obj *FilterFunc) Validate() error

Validate tells us if the input struct takes a valid form.

type MapFunc

type MapFunc struct {
	Type  *types.Type // this is the type of the elements in our input list
	RType *types.Type // this is the type of the elements in our output list
	// contains filtered or unexported fields
}

MapFunc is the standard map iterator function that applies a function to each element in a list. It returns a list with the same number of elements as the input list. There is no requirement that the element output type be the same as the input element type. This implements the signature: `func(inputs []?1, function func(?1) ?2) []?2` instead of the alternate with the two input args swapped, because while the latter is more common with languages that support partial function application, the former variant that we implemented is much more readable when using an inline lambda. TODO: should we extend this to support iterating over map's and structs, or should that be a different function? I think a different function is best.

func (*MapFunc) ArgGen

func (obj *MapFunc) ArgGen(index int) (string, error)

ArgGen returns the Nth arg name for this function.

func (*MapFunc) Build

func (obj *MapFunc) Build(typ *types.Type) (*types.Type, error)

Build is run to turn the polymorphic, undetermined function, into the specific statically typed version. It is usually run after Unify completes, and must be run before Info() and any of the other Func interface methods are used. This function is idempotent, as long as the arg isn't changed between runs.

func (*MapFunc) Copy

func (obj *MapFunc) Copy() interfaces.Func

Copy is implemented so that the type values are not lost if we copy this function.

func (*MapFunc) Info

func (obj *MapFunc) Info() *interfaces.Info

Info returns some static info about itself. Build must be called before this will return correct data.

func (*MapFunc) Init

func (obj *MapFunc) Init(init *interfaces.Init) error

Init runs some startup code for this function.

func (*MapFunc) Stream

func (obj *MapFunc) Stream(ctx context.Context) error

Stream returns the changing values that this func has over time.

func (*MapFunc) String

func (obj *MapFunc) String() string

String returns a simple name for this function. This is needed so this struct can satisfy the pgraph.Vertex interface.

func (*MapFunc) Validate

func (obj *MapFunc) Validate() error

Validate tells us if the input struct takes a valid form.

type RangeFunc

type RangeFunc struct {
	Type *types.Type
	// contains filtered or unexported fields
}

RangeFunc is a function that ranges over elements on a list according to three possible inputs: start, stop, and step. At least one input is needed, and in that case it's mapped to be the stop argument. Start is used for the function to build lists which start from a chosen number, and step to filter its contents to a subset of all the numbers between start and stop. This function only takes ints as inputs, and outputs a list of ints.

func (*RangeFunc) Build

func (obj *RangeFunc) Build(typ *types.Type) (*types.Type, error)

Build is run to turn the polymorphic, undetermined function, into the specific statically typed version. It is usually run after Unify completes, and must be run before Info() and any of the other Func interface methods are used. This function is idempotent, as long as the arg isn't changed between runs.

func (*RangeFunc) Call

func (obj *RangeFunc) Call(ctx context.Context, args []types.Value) (types.Value, error)

Call returns the result of this function.

func (*RangeFunc) Copy

func (obj *RangeFunc) Copy() interfaces.Func

Copy is implemented so that the obj.Type value is not lost if we copy this function.

func (*RangeFunc) FuncInfer

func (obj *RangeFunc) FuncInfer(partialType *types.Type, partialValues []types.Value) (*types.Type, []*interfaces.UnificationInvariant, error)

FuncInfer takes partial type and value information from the call site of this function so that it can build an appropriate type signature for it. The type signature may include unification variables.

func (*RangeFunc) Info

func (obj *RangeFunc) Info() *interfaces.Info

Info returns some static info about itself. Build must be called before this will return correct data

func (*RangeFunc) Init

func (obj *RangeFunc) Init(init *interfaces.Init) error

Init runs some startup code for this function.

func (*RangeFunc) Stream

func (obj *RangeFunc) Stream(ctx context.Context) error

Stream returns the changing values that this func has over time.

func (*RangeFunc) String

func (obj *RangeFunc) String() string

String returns a simple name for this function. This is needed so this struct can satisfy the pgraph.Vertex interface.

func (*RangeFunc) Validate

func (obj *RangeFunc) Validate() error

Validate tells us if the input struct takes a valid form.

Source Files

filter.go iter.go map.go range.go

Version
v0.0.0-20250526122833-2d78dc983617 (latest)
Published
May 26, 2025
Platform
linux/amd64
Imports
8 packages
Last checked
9 hours ago

Tools for package owners.