scope

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package scope provides types for modeling execution scopes, as well as simple namespaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RWScope

type RWScope[V any] struct {
	// contains filtered or unexported fields
}

RWScope stores key,value pairs and the Scope interface. A key, value pair is always defined within the scope. A value can retrieved from its key by querying the scope and, if not found, its parents recursively.

func NewScope

func NewScope[V any](parent Scope[V]) *RWScope[V]

NewScope returns a new scope given a parent, which can be nil.

func (*RWScope[V]) Assign

func (s *RWScope[V]) Assign(key string, value V) error

Assign maps an existing `key` to `value`, failing if no matching mapping is found. The assignment starts at the scope's innermost namespace and cascades upwards through successive parent scopes.

func (*RWScope[V]) CanAssign

func (s *RWScope[V]) CanAssign(key string) bool

CanAssign returns true if a key can be assigned.

func (*RWScope[V]) Define

func (s *RWScope[V]) Define(k string, v V)

Define maps `key` to `value`, overwriting if necessary.

func (*RWScope[V]) Find

func (s *RWScope[V]) Find(key string) (value V, ok bool)

Find a key in the scope and its parent.

func (*RWScope[V]) IsLocal added in v0.3.0

func (s *RWScope[V]) IsLocal(key string) bool

IsLocal returns true if the key is defined in the local scope.

func (*RWScope[V]) LocalKeys

func (s *RWScope[V]) LocalKeys() iter.Seq[string]

LocalKeys returns the keys of the local scope without the parent.

func (*RWScope[V]) ReadOnly

func (s *RWScope[V]) ReadOnly() Scope[V]

ReadOnly returns a scope to which values cannot be assigned or defined.

func (*RWScope[V]) String

func (s *RWScope[V]) String() string

String representation of the scope.

type Scope

type Scope[V any] interface {
	CanAssign(string) bool
	Find(string) (V, bool)
}

Scope provides a set of values that can be find given their name.

func NewReadOnly

func NewReadOnly[V any](parent, data Scope[V]) Scope[V]

NewReadOnly returns a scope that can only be queried and not modified.

func NewScopeWithValues

func NewScopeWithValues[V any](vals map[string]V) Scope[V]

NewScopeWithValues returns a scope with predefined values.

Jump to

Keyboard shortcuts

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