github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/docs/commands/a.md (about)

     1  # `a` (mkarray)
     2  
     3  > A sophisticated yet simple way to build an array or list
     4  
     5  ## Description
     6  
     7  Pronounced "make array", like `mkdir` (etc), Murex has a pretty sophisticated
     8  builtin for generating arrays. Think like bash's `{1..9}` syntax:
     9  
    10  ```
    11  a [1..9]
    12  ```
    13  
    14  Except Murex also supports other sets of ranges like dates, days of the week,
    15  and alternative number bases.
    16  
    17  ## Usage
    18  
    19  ```
    20  a: [start..end] -> <stdout>
    21  a: [start..end,start..end] -> <stdout>
    22  a: [start..end][start..end] -> <stdout>
    23  ```
    24  
    25  All usages also work with `ja` and `ta` as well, eg:
    26  
    27  ```
    28  ja: [start..end] -> <stdout>
    29  ta: data-type [start..end] -> <stdout>
    30  ```
    31  
    32  You can also inline arrays with the `%[]` syntax, eg:
    33  
    34  ```
    35  %[start..end]
    36  ```
    37  
    38  ## Examples
    39  
    40  ```
    41  » a [1..3]
    42  1
    43  2
    44  3
    45  
    46  » a [3..1]
    47  3
    48  2
    49  1
    50  
    51  » a [01..03]
    52  01
    53  02
    54  03
    55  ```
    56  
    57  ## Detail
    58  
    59  ### Advanced Array Syntax
    60  
    61  The syntax for `a` is a comma separated list of parameters with expansions
    62  stored in square brackets. You can have an expansion embedded inside a
    63  parameter or as it's own parameter. Expansions can also have multiple
    64  parameters.
    65  
    66  ```
    67  » a 01,02,03,05,06,07
    68  01
    69  02
    70  03
    71  05
    72  06
    73  07
    74  ```
    75  
    76  ```
    77  » a 0[1..3],0[5..7]
    78  01
    79  02
    80  03
    81  05
    82  06
    83  07
    84  ```
    85  
    86  ```
    87  » a 0[1..3,5..7]
    88  01
    89  02
    90  03
    91  05
    92  06
    93  07
    94  ```
    95  
    96  ```
    97  » a b[o,i]b
    98  bob
    99  bib
   100  ```
   101  
   102  You can also have multiple expansion blocks in a single parameter:
   103  
   104  ```
   105  » a a[1..3]b[5..7]
   106  a1b5
   107  a1b6
   108  a1b7
   109  a2b5
   110  a2b6
   111  a2b7
   112  a3b5
   113  a3b6
   114  a3b7
   115  ```
   116  
   117  `a` will cycle through each iteration of the last expansion, moving itself
   118  backwards through the string; behaving like an normal counter.
   119  
   120  ### Creating JSON arrays with `ja`
   121  
   122  As you can see from the previous examples, `a` returns the array as a
   123  list of strings. This is so you can stream excessively long arrays, for
   124  example every IPv4 address: `a: [0..254].[0..254].[0..254].[0..254]`
   125  (this kind of array expansion would hang bash).
   126  
   127  However if you needed a JSON string then you can use all the same syntax
   128  as `a` but forgo the streaming capability:
   129  
   130  ```
   131  » ja [Monday..Sunday]
   132  [
   133      "Monday",
   134      "Tuesday",
   135      "Wednesday",
   136      "Thursday",
   137      "Friday",
   138      "Saturday",
   139      "Sunday"
   140  ]
   141  ```
   142  
   143  This is particularly useful if you are adding formatting that might break
   144  under `a`'s formatting (which uses the `str` data type).
   145  
   146  ### Smart arrays
   147  
   148  Murex supports a number of different formats that can be used to generate
   149  arrays. For more details on these please refer to the documents for each format
   150  
   151  * [Calendar Date Ranges](../mkarray/date.md):
   152    Create arrays of dates
   153  * [Character arrays](../mkarray/character.md):
   154    Making character arrays (a to z)
   155  * [Decimal Ranges](../mkarray/decimal.md):
   156    Create arrays of decimal integers
   157  * [Non-Decimal Ranges](../mkarray/non-decimal.md):
   158    Create arrays of integers from non-decimal number bases
   159  * [Special Ranges](../mkarray/special.md):
   160    Create arrays from ranges of dictionary terms (eg weekdays, months, seasons, etc)
   161  
   162  ## See Also
   163  
   164  * [`%[]` Create Array](../parser/create-array.md):
   165    Quickly generate arrays
   166  * [`[ ..Range ]`](../parser/range.md):
   167    Outputs a ranged subset of data from STDIN
   168  * [`[ Index ]`](../parser/item-index.md):
   169    Outputs an element from an array, map or table
   170  * [`[[ Element ]]`](../parser/element.md):
   171    Outputs an element from a nested structure
   172  * [`count`](../commands/count.md):
   173    Count items in a map, list or array
   174  * [`ja` (mkarray)](../commands/ja.md):
   175    A sophisticated yet simply way to build a JSON array
   176  * [`mtac`](../commands/mtac.md):
   177    Reverse the order of an array
   178  * [`str` (string)](../types/str.md):
   179    string (primitive)
   180  * [`ta` (mkarray)](../commands/ta.md):
   181    A sophisticated yet simple way to build an array of a user defined data-type
   182  
   183  <hr/>
   184  
   185  This document was generated from [builtins/core/mkarray/array_doc.yaml](https://github.com/lmorg/murex/blob/master/builtins/core/mkarray/array_doc.yaml).