ReadNotIndex()
(type)Data type handler for the bang-prefixed index,
![
, builtin
This is a function you would write when programming a murex data-type.
It's called by the index, ![
, builtin.
The purpose of this function is to allow builtins to support sequential reads (where possible) and also create a standard interface for ![
(index), thus allowing it to be data-type agnostic.
Registering your ReadNotIndex()
// To avoid data races, this should only happen inside func init()
lang.ReadNotIndexes[ /* your type name */ ] = /* your readIndex func */
Example ReadIndex()
function (the code structure is the same for ReadIndex
and ReadNotIndex
):
package json
import (
"github.com/lmorg/murex/lang"
"github.com/lmorg/murex/utils/json"
)
func index(p *lang.Process, params []string) error {
var jInterface interface{}
b, err := p.Stdin.ReadAll()
if err != nil {
return err
}
err = json.Unmarshal(b, &jInterface)
if err != nil {
return err
}
marshaller := func(iface interface{}) ([]byte, error) {
return json.Marshal(iface, p.Stdout.IsTTY())
}
return lang.IndexTemplateObject(p, params, &jInterface, marshaller)
}
While there is support for a dedicated ReadNotIndex()
for instances of ![
, the template APIs lang.IndexTemplateObject
and lang.IndexTemplateTable
are both agnostic to the bang prefix.
*lang.Process
: Process's runtime state. Typically expressed as the variable p
[]string
: slice of parameters used in ![
ReadArray()
(type): Read from a data type one array element at a timeReadIndex()
(type): Data type handler for the index, [
, builtinWriteArray()
(type): Write a data type, one array element at a time[[
(element): Outputs an element from a nested structure[
(index): Outputs an element from an array, map or tablelang.IndexTemplateObject()
(template API): Returns element(s) from a data structurelang.IndexTemplateTable()
(template API): Returns element(s) from a tableThis site's content is rebuilt automatically from murex's source code after each merge to the master
branch. Downloadable murex binaries are also built with the website.
Last built on Thu May 26 22:49:43 UTC 2022 against commit 59e27bb59e27bb1013043fc4a940cf9a2767c63f31dad2c.
Current version is 2.8.2100 which has been verified against 15889 tests cases.