murex Shell Docs

API Reference: ReadArray() (type)

Read from a data type one array element at a time


This is a function you would write when programming a murex data-type.

It's called by builtins to allow them to read data structures one array element at a time.

The purpose of this function is to allow builtins to support sequential reads (where possible) and also create a standard interface for builtins, thus allowing them to be data-type agnostic.


Registering your ReadArray()

// To avoid confusion, this should only happen inside func init()
stdio.RegisterReadArray(/* your type name */, /* your readArray func */)


Example ReadArray() function:

package string

import (


func readArray(read stdio.Io, callback func([]byte)) error {
    scanner := bufio.NewScanner(read)
    for scanner.Scan() {

    return scanner.Err()


If your data type is not a stream-able array, it is then recommended that you pass your array to lang.ArrayTemplate() which is a handler to convert Go structures into murex arrays. This also makes writing ReadArray() handlers easier since you can just pass lang.ArrayTemplate() your marshaller. For example:

package json

import (

func readArray(read stdio.Io, callback func([]byte)) error {
    // Create a marshaller function to pass to ArrayTemplate
    marshaller := func(v interface{}) ([]byte, error) {
        return json.Marshal(v, read.IsTTY())

    return lang.ArrayTemplate(marshaller, json.Unmarshal, read, callback)

The downside of this is that you're then unmarshalling the entire file, which could be slow on large files and also breaks the streaming nature of UNIX pipelines.


  1. stdio.Io: stream to read from (eg STDIN)
  2. func([]byte): callback function. Each callback will be a []byte slice containing an array element

See Also

This 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 Wed Jan 12 10:38:51 UTC 2022 against commit 50d6f4550d6f45b79e200b3cbc8e8e2639854a5265c7021.

Current version is 2.4.3010 BETA which has been verified against tests.