github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/lang/stdio/interface_doc.yaml (about)

     1  - DocumentID: ReadArray
     2    Title: >-
     3      `ReadArray()` (type)
     4    CategoryID: apis
     5    Summary: >-
     6      Read from a data type one array element at a time
     7    Description: |-
     8      This is a function you would write when programming a Murex data-type.
     9      
    10      It's called by builtins to allow them to read data structures one array element
    11      at a time.
    12      
    13      The purpose of this function is to allow builtins to support sequential reads
    14      (where possible) and also create a standard interface for builtins, thus
    15      allowing them to be data-type agnostic.
    16    Usage: |-
    17      Registering your `ReadArray()`
    18      
    19      ```go
    20      // To avoid confusion, this should only happen inside func init()
    21      stdio.RegisterReadArray(/* your type name */, /* your readArray func */)
    22      ```
    23    Examples: |-
    24      Example `ReadArray()` function:
    25  
    26      ```go
    27      {{ include "builtins/types/string/array_read.go" }}
    28      ```
    29    Detail: |-
    30      If your data type is not a stream-able array, it is then recommended that
    31      you pass your array to  `lang.ArrayTemplate()` which is a handler to convert Go
    32      structures into Murex arrays. This also makes writing `ReadArray()` handlers
    33      easier since you can just pass `lang.ArrayTemplate()` your marshaller.
    34      For example:
    35  
    36      ```go
    37      {{ include "builtins/types/json/array_read.go" }}
    38      ```
    39  
    40      The downside of this is that you're then unmarshalling the entire file, which
    41      could be slow on large files and also breaks the streaming nature of UNIX
    42      pipelines.
    43    Parameters:
    44    - "`stdio.Io`: stream to read from (eg STDIN)"
    45    - "`func([]byte)`: callback function. Each callback will be a []byte slice containing an array element"
    46    Related:
    47    - WriteArray
    48    - ReadMap
    49    - lang.ArrayTemplate
    50    - lang.ArrayWithTypeTemplate
    51    - ReadIndex
    52    - ReadNotIndex
    53  
    54  
    55  - DocumentID: lang.ArrayTemplate
    56    Title: >-
    57      `lang.ArrayTemplate()` (template API)
    58    CategoryID: apis
    59    Summary: >-
    60      Unmarshals a data type into a Go struct and returns the results as an array
    61    Description: |-
    62      This is a template API you can use for your custom data types to wrap around an
    63      existing Go marshaller and return a Murex array which is consistent with
    64      other structures such as nested JSON or YAML documents.
    65  
    66      It should only be called from `ReadArray()` functions.
    67  
    68      Because `lang.ArrayTemplate()` relies on a marshaller, it means any types that
    69      rely on this API are not going to be stream-able.
    70    Usage:
    71    Examples: |-
    72      Example calling `lang.ArrayTemplate()` function:
    73  
    74      ```go
    75      {{ include "builtins/types/json/array_read.go" }}
    76      ```
    77    Detail: |-
    78      ### API Source:
    79  
    80      ```go
    81      {{ include "lang/define_array.go" }}
    82      ```
    83    Parameters:
    84    - "`func(interface{}) ([]byte, error)`: data type's marshaller"
    85    - "`func([]byte, interface{}) error`: data type's unmarshaller"
    86    - "`stdio.Io`: stream to read from (eg STDIN)"
    87    - "`func([]byte)`: callback function to write each array element"
    88    Related:
    89    - ReadArray
    90    - ReadArrayWithType
    91    - WriteArray
    92    - ReadMap
    93    - ReadIndex
    94    - ReadNotIndex
    95    - lang.IndexTemplateObject
    96    - lang.IndexTemplateTable
    97  
    98  
    99  - DocumentID: ReadArrayWithType
   100    Title: >-
   101      `ReadArrayWithType()` (type)
   102    CategoryID: apis
   103    Summary: >-
   104      Read from a data type one array element at a time and return the elements
   105      contents and data type
   106    Description: |-
   107      This is a function you would write when programming a Murex data-type.
   108      
   109      It's called by builtins to allow them to read data structures one array element
   110      at a time.
   111      
   112      The purpose of this function is to allow builtins to support sequential reads
   113      (where possible) and also create a standard interface for builtins, thus
   114      allowing them to be data-type agnostic.
   115      
   116      This differs from ReadArray() because it also returns the data type.
   117  
   118      There is a good chance ReadArray() might get deprecated in the medium to long
   119      term.
   120    Usage: |-
   121      Registering your `ReadArrayWithType()`
   122      
   123      ```go
   124      // To avoid confusion, this should only happen inside func init()
   125      stdio.RegisterReadArrayWithType(/* your type name */, /* your readArray func */)
   126      ```
   127    Examples: |-
   128      Example `ReadArrayWithType()` function:
   129  
   130      ```go
   131      {{ include "builtins/types/string/array_read_type.go" }}
   132      ```
   133    Detail: |-
   134      If your data type is not a stream-able array, it is then recommended that
   135      you pass your array to  `lang.ArrayWithTypeTemplate()` which is a handler to
   136      convert Go structures into Murex arrays. This also makes writing `ReadArray()`
   137      handlers easier since you can just pass `lang.ArrayTemplate()` your marshaller.
   138      For example:
   139  
   140      ```go
   141      {{ include "builtins/types/json/array_read_type.go" }}
   142      ```
   143  
   144      The downside of this is that you're then unmarshalling the entire file, which
   145      could be slow on large files and also breaks the streaming nature of UNIX
   146      pipelines.
   147    Parameters:
   148    - "`stdio.Io`: stream to read from (eg STDIN)"
   149    - "`func(interface{}, string)`: callback function. Each callback will be the value in its native Go data type (eg string, int, float64, bool) for an array element"
   150    Related:
   151    - WriteArray
   152    - ReadMap
   153    - lang.ArrayTemplate
   154    - lang.ArrayWithTypeTemplate
   155    - ReadIndex
   156    - ReadNotIndex
   157  
   158  
   159  - DocumentID: lang.ArrayWithTypeTemplate
   160    Title: >-
   161      `lang.ArrayWithTypeTemplate()` (template API)
   162    CategoryID: apis
   163    Summary: >-
   164      Unmarshals a data type into a Go struct and returns the results as an array
   165      with data type included
   166    Description: |-
   167      This is a template API you can use for your custom data types to wrap around an
   168      existing Go marshaller and return a Murex array which is consistent with
   169      other structures such as nested JSON or YAML documents.
   170  
   171      It should only be called from `ReadArrayWithType()` functions.
   172  
   173      Because `lang.ArrayTemplateWithType()` relies on a marshaller, it means any types that
   174      rely on this API are not going to be stream-able.
   175    Usage:
   176    Examples: |-
   177      Example calling `lang.ArrayTemplate()` function:
   178  
   179      ```go
   180      {{ include "builtins/types/json/array_read.go" }}
   181      ```
   182    Detail: |-
   183      ### API Source:
   184  
   185      ```go
   186      {{ include "lang/define_array_type.go" }}
   187      ```
   188    Parameters:
   189    - "`func(interface{}) ([]byte, error)`: data type's marshaller"
   190    - "`func([]byte, interface{}) error`: data type's unmarshaller"
   191    - "`stdio.Io`: stream to read from (eg STDIN)"
   192    - "`func(interface{}, string)`: callback function to write each array element, with data type"
   193    Related:
   194    - ReadArrayWithType
   195    - ReadArray
   196    - WriteArray
   197    - ReadMap
   198    - ReadIndex
   199    - ReadNotIndex
   200    - lang.IndexTemplateObject
   201    - lang.IndexTemplateTable
   202  
   203  
   204  
   205  - DocumentID: WriteArray
   206    Title: >-
   207      `WriteArray()` (type)
   208    CategoryID: apis
   209    Summary: >-
   210      Write a data type, one array element at a time
   211    Description: |-
   212      This is a function you would write when programming a Murex data-type.
   213      
   214      It's called by builtins to allow them to write data structures one array
   215      element at a time.
   216  
   217      The purpose of this function is to allow builtins to support sequential writes
   218      (where possible) and also create a standard interface for builtins, thus
   219      allowing them to be data-type agnostic.
   220  
   221      ### A Collection of Functions
   222  
   223      `WriteArray()` should return a `struct` that satisfies the following
   224      `interface{}`:
   225      
   226      ```go
   227      {{ include "lang/stdio/interface_aw.go" }}
   228      ```
   229    Usage: |-
   230      Registering your `WriteArray()`
   231      
   232      ```go
   233      // To avoid confusion, this should only happen inside func init()
   234      stdio.RegisterWriteArray(/* your type name */, /* your writeArray func */)
   235      ```
   236    Examples: |-
   237      Example `WriteArray()` function:
   238  
   239      ```go
   240      {{ include "builtins/types/string/array_write.go" }}
   241      ```
   242    Detail: |-
   243      Since not all data types will be stream-able (for example `json`), some types
   244      may need to cache the array and then to write it once the array writer has been
   245      closed.
   246  
   247      ```go
   248      {{ include "builtins/types/json/array_write.go" }}
   249      ```
   250    Related:
   251    - ReadArray
   252    - ReadArrayWithType
   253    - ReadMap
   254    - ReadIndex
   255    - ReadNotIndex
   256  
   257  - DocumentID: ReadMap
   258    Title: >-
   259      `ReadMap()` (type)
   260    CategoryID: apis
   261    Summary: >-
   262      Treat data type as a key/value structure and read its contents
   263    Description: |-
   264      This is a function you would write when programming a Murex data-type.
   265      
   266      It's called by builtins to allow them to read data structures one key/value
   267      pair at a time.
   268  
   269      The purpose of this function is to allow builtins to support sequential reads
   270      (where possible) and also create a standard interface for builtins, thus
   271      allowing them to be data-type agnostic.
   272    Usage: |-
   273      Registering your `ReadMap()`
   274      
   275      ```go
   276      // To avoid confusion, this should only happen inside func init()
   277      stdio.RegisterReadMap(/* your type name */, /* your readMap func */)
   278      ```
   279    Examples: |-
   280      Example `ReadMap()` function:
   281  
   282      ```go
   283      {{ include "builtins/types/json/map.go" }}
   284      ```
   285    Detail: |-
   286      There isn't (yet) a template read function for types to call. However that
   287      might follow in a future release of Murex.
   288    Parameters:
   289    - "`stdio.Io`: stream to read from (eg STDIN)"
   290    - "`*config.Config`: scoped config (eg your data type might have configurable parsing rules)"
   291    - "`func(key, value string, last bool)`: callback function: key and value of map plus boolean which is true if last element in row (eg reading from tables rather than key/values)"
   292    Related:
   293    - ReadArray
   294    - ReadArrayWithType
   295    - WriteArray
   296    - ReadIndex
   297    - ReadNotIndex
   298  
   299  
   300  - DocumentID: ReadIndex
   301    Title: >-
   302      `ReadIndex()` (type)
   303    CategoryID: apis
   304    Summary: >-
   305      Data type handler for the index, `[`, builtin
   306    Description: |-
   307      This is a function you would write when programming a Murex data-type.
   308      
   309      It's called by the index, `[`, builtin.
   310  
   311      The purpose of this function is to allow builtins to support sequential reads
   312      (where possible) and also create a standard interface for `[` (index), thus
   313      allowing it to be data-type agnostic.
   314    Usage: |-
   315      Registering your `ReadIndex()`
   316      
   317      ```go
   318      // To avoid data races, this should only happen inside func init()
   319      lang.ReadIndexes[ /* your type name */ ] = /* your readIndex func */
   320      ```
   321    Examples: |-
   322      Example `ReadIndex()` function:
   323  
   324      ```go
   325      {{ include "builtins/types/json/index.go" }}
   326      ```
   327    Detail: |-
   328      While there is support for a dedicated `ReadNotIndex()` for instances of `![`,
   329      the template APIs `lang.IndexTemplateObject` and `lang.IndexTemplateTable` are
   330      both agnostic to the bang prefix.
   331    Parameters:
   332    - "`*lang.Process`: Process's runtime state. Typically expressed as the variable `p` "
   333    - "`[]string`: slice of parameters used in `[` "
   334    Related:
   335    - ReadArray
   336    - ReadArrayWithType
   337    - WriteArray
   338    - lang.IndexTemplateObject
   339    - lang.IndexTemplateTable
   340    - ReadNotIndex
   341    - index
   342    - element
   343    - bang-prefix
   344  
   345  
   346  
   347  - DocumentID: ReadNotIndex
   348    Title: >-
   349      `ReadNotIndex()` (type)
   350    CategoryID: apis
   351    Summary: >-
   352      Data type handler for the bang-prefixed index, `![`, builtin
   353    Description: |-
   354      This is a function you would write when programming a Murex data-type.
   355      
   356      It's called by the index, `![`, builtin.
   357  
   358      The purpose of this function is to allow builtins to support sequential reads
   359      (where possible) and also create a standard interface for `![` (index), thus
   360      allowing it to be data-type agnostic.
   361    Usage: |-
   362      Registering your `ReadNotIndex()`
   363      
   364      ```go
   365      // To avoid data races, this should only happen inside func init()
   366      lang.ReadNotIndexes[ /* your type name */ ] = /* your readIndex func */
   367      ```
   368    Examples: |-
   369      Example `ReadIndex()` function (the code structure is the same for `ReadIndex`
   370      and `ReadNotIndex`):
   371  
   372      ```go
   373      {{ include "builtins/types/json/index.go" }}
   374      ```
   375    Detail: |-
   376      While there is support for a dedicated `ReadNotIndex()` for instances of `![`,
   377      the template APIs `lang.IndexTemplateObject` and `lang.IndexTemplateTable` are
   378      both agnostic to the bang prefix.
   379    Parameters:
   380    - "`*lang.Process`: Process's runtime state. Typically expressed as the variable `p` "
   381    - "`[]string`: slice of parameters used in `![` "
   382    Related:
   383    - ReadArray
   384    - ReadArrayWithType
   385    - WriteArray
   386    - lang.IndexTemplateObject
   387    - lang.IndexTemplateTable
   388    - ReadIndex
   389    - index
   390    - element
   391    - bang-prefix
   392  
   393  
   394  - DocumentID: lang.IndexTemplateObject
   395    Title: >-
   396      `lang.IndexTemplateObject()` (template API)
   397    CategoryID: apis
   398    Summary: >-
   399      Returns element(s) from a data structure
   400    Description: |-
   401      This is a template API you can use for your custom data types.
   402  
   403      It should only be called from `ReadIndex()` and `ReadNotIndex()` functions.
   404  
   405      This function ensures consistency with the index, `[`, builtin when used with
   406      different Murex data types. Thus making indexing a data type agnostic
   407      capability.
   408    Usage:
   409    Examples: |-
   410      Example calling `lang.IndexTemplateObject()` function:
   411  
   412      ```go
   413      {{ include "builtins/types/json/index.go" }}
   414      ```
   415    Detail: |-
   416      ### API Source:
   417  
   418      ```go
   419      {{ include "lang/define_index_objects.go" }}
   420      ```
   421    Parameters:
   422    - "`*lang.Process`: Process's runtime state. Typically expressed as the variable `p` "
   423    - "`[]string`: slice of parameters used in `[` / `![` "
   424    - "`*interface{}`: a pointer to the data structure being indexed"
   425    - "`func(interface{}) ([]byte, error)`: data type marshaller function"
   426    Related:
   427    - ReadArray
   428    - ReadArrayWithType
   429    - WriteArray
   430    - ReadMap
   431    - ReadIndex
   432    - ReadNotIndex
   433    - lang.IndexTemplateTable
   434    - index
   435  
   436  
   437  - DocumentID: lang.IndexTemplateTable
   438    Title: >-
   439      `lang.IndexTemplateTable()` (template API)
   440    CategoryID: apis
   441    Summary: >-
   442      Returns element(s) from a table
   443    Description: |-
   444      This is a template API you can use for your custom data types.
   445  
   446      It should only be called from `ReadIndex()` and `ReadNotIndex()` functions.
   447  
   448      This function ensures consistency with the index, `[`, builtin when used with
   449      different Murex data types. Thus making indexing a data type agnostic
   450      capability.
   451    Usage:
   452    Examples: |-
   453      Example calling `lang.IndexTemplateTable()` function:
   454  
   455      ```go
   456      {{ include "builtins/types/generic/index.go" }}
   457      ```
   458    Detail: |-
   459      ### API Source:
   460  
   461      ```go
   462      {{ include "lang/define_index_tables.go" }}
   463      ```
   464    Parameters:
   465    - "`*lang.Process`: Process's runtime state. Typically expressed as the variable `p` "
   466    - "`[]string`: slice of parameters used in `[` / `![` "
   467    - "`chan []string`: a channel for rows (each element in the slice is a column within the row). This allows tables to be stream-able"
   468    - "`func(interface{}) ([]byte, error)`: data type marshaller function"
   469    Related:
   470    - ReadArray
   471    - ReadArrayWithType
   472    - WriteArray
   473    - ReadMap
   474    - ReadIndex
   475    - ReadNotIndex
   476    - lang.IndexTemplateObject
   477    - index
   478  
   479