scoped

package
v0.28.21 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package scoped provides a mapping from a string to any data type that is "scoped".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ParamValue added in v0.28.0

type ParamValue struct {
	Scope, Key string
	Value      any
}

ParamValue is returned by Params.Iter()

type Params

type Params struct {
	Separator string
	// contains filtered or unexported fields
}

Params provides a mapping from string to any data type that is "scoped":

  • For every scope there is a map of string to data.
  • Accessing a key triggers a search from the current scope up to the root scope, the first result found is returned.

Example: let's say the current Params hold:

Scope: "/": { "x":10, "y": 20, "z": 40 }
Scope: "/a": { "y": 30 }
Scope: "/a/b": { "x": 100 }

Params.Get("/a/b", "x") -> 100
Params.Get("/a/b", "y") -> 30
Params.Get("/a/b", "z") -> 40
Params.Get("/a/b", "w") -> Not found.

Notice that "/" (== ScopeSeparator constant) separates parts of the scope path, and the root scope is referred to as "/". There is no "empty" scope, and every scope name must start with a ScopeSeparator.

The Context object uses Params to store the normal hyperparameters (see `Context.GetParam` and `Context.SetParam`) and to store the graph hyperparameters (see `Context.GetGraphParam` and `Context.SetGraphParam`).

Usually there will be no need for the end user to use this.

func New

func New(scopeSeparator string) *Params

New create an empy scopedParams.

func (*Params) Clone

func (p *Params) Clone() *Params

Clone returns a deep copy of the scopedParams.

func (*Params) Enumerate

func (p *Params) Enumerate(fn func(scope, key string, value any))

Enumerate enumerates all parameters stored in the scopedParams structure and calls the given closure with them.

func (*Params) Get

func (p *Params) Get(scope, key string) (value any, found bool)

Get retrieves the value for the given key in the given scope or any parent scope. E.g: Get("/a/b", "myKey") will search for "myKey" in scopes "/a/b", "/a" and "/" consecutively until "myKey" is found.

It returns the first value found if any, and whether some value was found.

func (*Params) Iter added in v0.28.0

func (p *Params) Iter() iter.Seq[ParamValue]

Iter returns an iterator over all parameters.

func (*Params) Set

func (p *Params) Set(scope, key string, value any)

Set sets the value for the given key, in the given scope.

Jump to

Keyboard shortcuts

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