Documentation ¶
Index ¶
- Variables
- func AdaptError(err error) jpl.JPLError
- func AlterJPLType(t jpl.JPLType, updater jpl.JPLModifier) (any, jpl.JPLError)
- func AlterValue(value any, updater jpl.JPLModifier) (any, jpl.JPLError)
- func ApplyArray[Value any](source []Value, changes []*ArrayEntry[Value], filler Value) []Value
- func ApplyCombinations[Value any](source []Value, combinations [][]Value) [][]Value
- func ApplyObject[Value any](source map[string]Value, changes []*ObjectEntry[Value]) map[string]Value
- func AssertType(value any, expectedType jpl.JPLDataType) (any, jpl.JPLError)
- func Compare(a, b any) (int, jpl.JPLError)
- func CompareArrays(a, b any) (int, jpl.JPLError)
- func CompareObjects(a, b any) (int, jpl.JPLError)
- func CompareStrings(a, b any) (int, jpl.JPLError)
- func CopyMap[Key comparable, Value any](source map[Key]Value) (result map[Key]Value)
- func CopySlice[Value any](source []Value) (result []Value)
- func DisplayValue(value any) (string, jpl.JPLError)
- func Equals(a, b any) (bool, jpl.JPLError)
- func GetMapKeys[Key comparable, Value any](source map[Key]Value) []Key
- func GetMapValues[Key comparable, Value any](source map[Key]Value) []Value
- func IsSame(a, b any) bool
- func MarshalJPLType(t jpl.JPLType) ([]byte, jpl.JPLError)
- func Merge(a, b any) (any, jpl.JPLError)
- func MergeMaps[Key comparable, Value any](sources ...map[Key]Value) (result map[Key]Value)
- func MergeSegments[Value any](segments [][]Value) []Value
- func Mux[Input any](args [][]Input, cb jpl.IMuxer[Input]) jpl.JPLError
- func MuxAll[Input any, Output any](args [][]Input, cb jpl.IOMuxer[Input, []Output]) ([]Output, jpl.JPLError)
- func MuxOne[Input any, Output any](args [][]Input, cb jpl.IOMuxer[Input, Output]) ([]Output, jpl.JPLError)
- func NativeFunction(fn func(runtime jpl.JPLRuntime, input any, args ...any) ([]any, error)) jpl.JPLFunc
- func NewError(message string, name string) jpl.JPLError
- func NewErrorEnclosure(inner jpl.JPLError) jpl.JPLErrorEnclosure
- func NewExecutionError(message string, name string) jpl.JPLExecutionError
- func NewFatalError(message string) jpl.JPLFatalError
- func NewPiperWithScope(piper jpl.JPLPiper) jpl.JPLScopedPiper
- func NewPiperWithoutScope(piper jpl.JPLScopedPiper, scope jpl.JPLRuntimeScope) jpl.JPLPiper
- func NewReferenceError(value any, replacements ...any) (jpl.JPLReferenceError, jpl.JPLError)
- func NewRuntimeError(value any, replacements ...any) (jpl.JPLRuntimeError, jpl.JPLError)
- func NewRuntimeScope(presets *jpl.JPLRuntimeScopeConfig) jpl.JPLRuntimeScope
- func NewRuntimeSignal(parent jpl.JPLRuntimeSignal) jpl.JPLRuntimeSignal
- func NewSyntaxError(message string) jpl.JPLSyntaxError
- func NewType(value any) (jpl.JPLType, jpl.JPLError)
- func NewTypeConversionError(value any, replacements ...any) (jpl.JPLTypeConversionError, jpl.JPLError)
- func NewTypeError(value any, replacements ...any) (jpl.JPLTypeError, jpl.JPLError)
- func NewZeroDivisionError(value any, replacements ...any) (jpl.JPLZeroDivisionError, jpl.JPLError)
- func Normalize(value any) (any, jpl.JPLError)
- func NormalizeValue(value any) (any, jpl.JPLError)
- func NormalizeValues(values any, name string) ([]any, jpl.JPLError)
- func ObjectFromEntries[Value any](entries []*ObjectEntry[Value]) map[string]Value
- func OrphanFunction(argNames []string, instructions definition.Pipe, ...) jpl.JPLFunc
- func ScopedFunction(argNames []string, instructions definition.Pipe, scope jpl.JPLRuntimeScope) jpl.JPLFunc
- func StrictDisplayValue(value any) (string, jpl.JPLError)
- func Stringify(value any, unescapeString bool, escapeFunctions bool) (string, jpl.JPLError)
- func StringifyJSON(value any, unescapeString bool) (string, jpl.JPLError)
- func Strip(value any, replacer jpl.JPLReplacer, stripper jpl.JPLStripper) (any, jpl.JPLError)
- func StripJSON(value any) (any, jpl.JPLError)
- func StripValue(value any) (any, jpl.JPLError)
- func StripValues(values any, name string) ([]any, jpl.JPLError)
- func SubSlice[Value any](source []Value, from int, to int) []Value
- func Template(tmpl any, replacements ...any) (string, jpl.JPLError)
- func ThrowAny[ErrorType jpl.JPLError](err1 ErrorType, err2 jpl.JPLError) jpl.JPLError
- func Truthy(value any) (bool, jpl.JPLError)
- func Type(value any) (jpl.JPLDataType, jpl.JPLError)
- func TypeOf(value any) (jpl.JPLDataType, jpl.JPLError)
- func Unwrap(value any) (any, jpl.JPLError)
- func UnwrapValue(value any) (any, jpl.JPLError)
- func UnwrapValues(values any, name string) ([]any, jpl.JPLError)
- type ArrayEntry
- type JPLPiperMuxer
- type JPLScopedPiperMuxer
- type ObjectEntry
Constants ¶
This section is empty.
Variables ¶
var JPLJSONStripper = jpl.JPLStripperFunc(func(k *string, v any, iter jpl.IterFunc) (result any, remove bool, err jpl.JPLError) { r := v if t, ok := v.(jpl.JPLType); ok { var err jpl.JPLError if r, err = t.JSON(); err != nil { return nil, false, err } } return RawStripper(k, r, iter) })
Stripper that allows JSON like values and unwraps JPLTypes
var JPLStripper = jpl.JPLStripperFunc(func(k *string, v any, iter jpl.IterFunc) (result any, remove bool, err jpl.JPLError) { r := v if t, ok := v.(jpl.JPLType); ok { var err jpl.JPLError if r, err = t.JSON(); err != nil { return nil, false, err } } if _, ok := v.(jpl.JPLFunc); ok { return r, false, nil } return RawStripper(k, r, iter) })
Stripper that only allows normalized values and unwraps JPLTypes
var JPLTypedStripper = jpl.JPLStripperFunc(func(k *string, v any, iter jpl.IterFunc) (result any, remove bool, err jpl.JPLError) { if _, ok := v.(jpl.JPLType); ok { return v, false, nil } if _, ok := v.(jpl.JPLFunc); ok { return v, false, nil } return RawStripper(k, v, iter) })
Stripper that allows JPLTypes and normalized values
var JSONStripper = jpl.JPLStripperFunc(func(k *string, v any, iter jpl.IterFunc) (result any, remove bool, err jpl.JPLError) { r := v if m, ok := r.(json.Marshaler); ok { bytes, err := m.MarshalJSON() if err != nil { return nil, false, AdaptError(err) } err = json.Unmarshal(bytes, &r) if err != nil { return nil, false, AdaptError(err) } } return RawStripper(k, r, iter) })
Stripper that allows JSON like values and parses `json.Marshaler` interfaces
var RawStripper = jpl.JPLStripperFunc(func(k *string, v any, iter jpl.IterFunc) (result any, remove bool, err jpl.JPLError) { top := k == nil switch v := v.(type) { case jpl.JPLFunc: return nil, !top, nil case string, bool: return v, false, nil case float64: if math.IsNaN(v) || math.IsInf(v, 0) { return nil, false, nil } return v, false, nil case []any: changes := make([]*ArrayEntry[any], len(v)) for i, entry := range v { key := strconv.Itoa(i) result, remove, err := iter(&key, entry) if err != nil { return nil, false, err } else if remove { result = nil } changes[i] = &ArrayEntry[any]{i, result} } return ApplyArray(v, changes, nil), false, nil case map[string]any: changes := make([]*ObjectEntry[any], 0, len(v)) for i, entry := range v { result, remove, err := iter(&i, entry) if err != nil { return nil, false, err } else if remove { result = nil } changes = append(changes, &ObjectEntry[any]{i, result, remove}) } return ApplyObject(v, changes), false, nil case nil: return nil, false, nil default: return nil, false, NewFatalError(fmt.Sprintf("unexpected %T", v)) } })
Stripper that allows JSON like values
Functions ¶
func AdaptError ¶
Wrap error in a JPLExecutionError if it is not already a JPLError
func AlterJPLType ¶
Alter the specified JPLType
func AlterValue ¶
Alter the specified normalized value using the specified updater
func ApplyArray ¶
func ApplyArray[Value any](source []Value, changes []*ArrayEntry[Value], filler Value) []Value
Apply all changes immutably to the source array. Indices can be negative to be applied from the end of the array.
func ApplyCombinations ¶
func ApplyCombinations[Value any](source []Value, combinations [][]Value) [][]Value
Create all possible combinations immutably. If the specified `combinations` array is empty, the resulting array contains a single empty array. This function has essentially the same base functionality as the `mux` function, but uses a more performant approach for generating immutable arrays as it reduces the number of necessary array copies.
`applyCombinations([], [[1, 2], [3, 4]])` for example produces: - `[1, 3]` - `[1, 4]` - `[2, 3]` - `[2, 4]`
If the values of `source` are equal to the values of one of the combinations, it is used instead of a copy in the output array, e.g.: `let i = [1, 2]; applyCombinations(i, [[1], [2]])[0] == i` - `true`
func ApplyObject ¶
func ApplyObject[Value any](source map[string]Value, changes []*ObjectEntry[Value]) map[string]Value
Apply all changes immutably to the source object.
func AssertType ¶
Assert the type for the specified unwrapped value
func CompareArrays ¶
Compare the specified normalized arrays based on their lexical order
func CompareObjects ¶
Compare the specified normalized objects
func CompareStrings ¶
Compare the specified normalized strings based on their unicode code points
func CopyMap ¶
func CopyMap[Key comparable, Value any](source map[Key]Value) (result map[Key]Value)
Copy the specified map
func CopySlice ¶
func CopySlice[Value any](source []Value) (result []Value)
Copy the specified slice
func DisplayValue ¶
Format the specified normalized value as a string
func GetMapKeys ¶
func GetMapKeys[Key comparable, Value any](source map[Key]Value) []Key
Return the specified map's keys
func GetMapValues ¶
func GetMapValues[Key comparable, Value any](source map[Key]Value) []Value
Return the specified map's values
func IsSame ¶
Check if both values are the same.
JPLTypes are compared by type and `JPLType.IsSame`, JPLFuncs, []any and map[string]any are compared by memory address, and other comparable values using `==`.
func MarshalJPLType ¶
Marshal the specified JPLType as JSON
func MergeMaps ¶
func MergeMaps[Key comparable, Value any](sources ...map[Key]Value) (result map[Key]Value)
Merge the specified maps into a single one
func MergeSegments ¶
func MergeSegments[Value any](segments [][]Value) []Value
Create a single array from the specified array segments
func Mux ¶
Multiplex the specified array of arguments by calling cb for all possible combinations of arguments.
`mux([[1,2], [3,4]], cb)` for example yields: - `cb(1, 3)` - `cb(1, 4)` - `cb(2, 3)` - `cb(2, 4)`
func MuxAll ¶
func MuxAll[Input any, Output any](args [][]Input, cb jpl.IOMuxer[Input, []Output]) ([]Output, jpl.JPLError)
Multiplex the specified array of arguments and return a single array of all merged result arrays produced by the callbacks
func MuxOne ¶
func MuxOne[Input any, Output any](args [][]Input, cb jpl.IOMuxer[Input, Output]) ([]Output, jpl.JPLError)
Multiplex the specified array of arguments and return the results produced by the callbacks
func NativeFunction ¶
func NativeFunction(fn func(runtime jpl.JPLRuntime, input any, args ...any) ([]any, error)) jpl.JPLFunc
Wrap the specified function to allow it to be used as a JPL function.
`next` must be called for each single result, which produces an array of results itself. All resulting results must be returned as a single array.
It is recommended to check the provided JPLRuntimeSignal in asynchronous routines to stop the routine when execution has been canceled: ``` if err := signal.CheckHealth(); err != nil { return nil, err } ```
func NewErrorEnclosure ¶
func NewErrorEnclosure(inner jpl.JPLError) jpl.JPLErrorEnclosure
func NewExecutionError ¶
func NewExecutionError(message string, name string) jpl.JPLExecutionError
func NewFatalError ¶
func NewFatalError(message string) jpl.JPLFatalError
func NewPiperWithScope ¶
func NewPiperWithScope(piper jpl.JPLPiper) jpl.JPLScopedPiper
A JPLPiper can be used in place of a JPLScopedPiper
func NewPiperWithoutScope ¶
func NewPiperWithoutScope(piper jpl.JPLScopedPiper, scope jpl.JPLRuntimeScope) jpl.JPLPiper
A JPLScopedPiper can be used in place of a JPLPiper
func NewReferenceError ¶
`value` can by of any type. If at least one replacement is specified, the value is formatted as a template.
func NewRuntimeError ¶
`value` can by of any type. If at least one replacement is specified, the value is formatted as a template.
func NewRuntimeScope ¶
func NewRuntimeScope(presets *jpl.JPLRuntimeScopeConfig) jpl.JPLRuntimeScope
func NewRuntimeSignal ¶
func NewRuntimeSignal(parent jpl.JPLRuntimeSignal) jpl.JPLRuntimeSignal
func NewSyntaxError ¶
func NewSyntaxError(message string) jpl.JPLSyntaxError
func NewTypeConversionError ¶
func NewTypeConversionError(value any, replacements ...any) (jpl.JPLTypeConversionError, jpl.JPLError)
`value` can by of any type. If at least one replacement is specified, the value is formatted as a template.
func NewTypeError ¶
`value` can by of any type. If at least one replacement is specified, the value is formatted as a template.
func NewZeroDivisionError ¶
`value` can by of any type. If at least one replacement is specified, the value is formatted as a template.
func NormalizeValue ¶
// Normalize the specified external value
func NormalizeValues ¶
Normalize the specified array of external values
func ObjectFromEntries ¶
func ObjectFromEntries[Value any](entries []*ObjectEntry[Value]) map[string]Value
func OrphanFunction ¶
func OrphanFunction(argNames []string, instructions definition.Pipe, presets *jpl.JPLRuntimeScopeConfig) jpl.JPLFunc
Create an orphan JPL function from the specified instructions.
Some optional scope presets may be specified, e.g. for allowing the function access to some specified variables. Other than that, the function does not have access to any external variables.
func ScopedFunction ¶
func ScopedFunction(argNames []string, instructions definition.Pipe, scope jpl.JPLRuntimeScope) jpl.JPLFunc
Create a scoped JPL function from the specified instructions.
The function is bound to the specified scope.
func StrictDisplayValue ¶
Format the specified normalized value as a string, without removing escaping
func StringifyJSON ¶
Stringify the specified normalized value for usage in program outputs
func Strip ¶
func Strip(value any, replacer jpl.JPLReplacer, stripper jpl.JPLStripper) (any, jpl.JPLError)
Unwrap the specified value similar to `JSON.stringify`. However, unlike with `JSON.stringify`, object member functions `toJSON` are not supported as they could interfere with user defined members. Instead, JPLTypes are being unwrapped by default.
A custom stripper can be provided to customize the behavior.
func StripValue ¶
Strip the specified normalized value for usage in JPL operations
func StripValues ¶
Strip the specified array of normalized values for usage in JPL operations
func SubSlice ¶
Return a sub slice of the specified slice.
`from` and `to` are allowed to be negative or to be outside of the range of `source`.
func Template ¶
Format the specified template string. The general form of a format is a percent sign, followed by optional flags, an optional width and a verb.
Examples: - `%10s`: Format the next replacement as a string and pads the result at the left with spaces to be at least 10 unicode codepoints long. - `%*<10v`: Format the next replacement as a JSON value and truncates it, if it is longer then 10 unicode codepoints.
The width specifies the desired field width and defaults to whatever is necessary to display the full replacement. If the width is specified without any other corresponding flags, it is used for padding the field if necessary.
Valid flags:
- `*`: Do not pad the value even if it is shorter than the specified width - `-`: Pad the value at the right rather than the left - `<`: Truncate the value at the right if it is too long for the specified width
Valid verbs:
- `%`: Returns a literal `%` - `s`: Format the next replacement as a string (like JSON, but does not escape strings) - `v`: Format the next replacement as a JSON value
func Truthy ¶
Determine whether the specified normalized value should be considered as truthy in JPL operations
func Type ¶
func Type(value any) (jpl.JPLDataType, jpl.JPLError)
Resolve the type of the specified normalized value for JPL operations
func TypeOf ¶
func TypeOf(value any) (jpl.JPLDataType, jpl.JPLError)
Resolve the type of the specified normalized value
func UnwrapValue ¶
Unwrap the specified normalized value for usage in JPL operations
Types ¶
type ArrayEntry ¶
func ArrayEntries ¶
func ArrayEntries[Value any](source []Value) []*ArrayEntry[Value]
type JPLPiperMuxer ¶
A JPLPiper can be used as an IOMuxer. For each argument, `JPLPiper.Pipe` is called and the results are combined into a single array.
func NewPiperMuxer ¶
func NewPiperMuxer(piper jpl.JPLPiper) JPLPiperMuxer
type JPLScopedPiperMuxer ¶
type JPLScopedPiperMuxer struct { jpl.JPLScopedPiper Scope jpl.JPLRuntimeScope }
A JPLScopedPiper can be used as an IOMuxer. For each argument, `JPLScopedPiper.Pipe` is called and the results are combined into a single array.
func NewScopedPiperMuxer ¶
func NewScopedPiperMuxer(piper jpl.JPLScopedPiper, scope jpl.JPLRuntimeScope) JPLScopedPiperMuxer
type ObjectEntry ¶
func FilteredObjectEntries ¶
func FilteredObjectEntries[Value any](source map[string]Value, ignoredKeys ...string) []*ObjectEntry[Value]
func ObjectEntries ¶
func ObjectEntries[Value any](source map[string]Value) []*ObjectEntry[Value]