Skip to main content

Arrays

Arrays store ordered collections of elements of the same type.

Syntax​

Type[]

Examples​

Type Declaration​

string[]           // array of strings
int[] // array of integers
MyClass[] // array of custom class
(int | string)[] // array of union type
int[][] // nested array (2D)

In Functions​

function DescriptionGame(items: string[]) -> string {
client "openai/gpt-4o-mini"
prompt #"
What 3 words best describe all of these: {{ items }}.
"#
}

In Tests​

Single-line format:

test FruitList {
functions [DescriptionGame]
args { items ["apple", "banana", "cherry"] }
}

Multi-line format:

test CityDescription {
functions [DescriptionGame]
args {
items [
"New York",
"Los Angeles",
"Chicago"
]
}
}

Nested Arrays​

Arrays can contain objects with key-value pairs:

{
key1 [value1, value2, value3],
key2 [
value1,
value2,
value3
],
key3 [
{
subkey1 "valueA",
subkey2 "valueB"
},
{
subkey1 "valueC",
subkey2 "valueD"
}
]
}

Key Points​

  • Commas are optional in multi-line arrays but recommended for clarity
  • Nested arrays are supported for complex data structures
  • Arrays can contain objects with key-value pairs
  • Array types can be nested to create multi-dimensional arrays
  • An array type cannot be optional (use Type[]? is invalid, use Type[] with empty array instead)

Language Equivalents​

BAMLPythonTypeScriptGo
string[]List[str]string[][]string
int[]List[int]number[][]int
(int | float)[]List[Union[int, float]]number[][]Union2IntOrFloat

See Also​