1///|
2fn moonbit_get_cli_args() -> type FixedArray[A]
FixedArray[Bytes
Bytes] = "$moonbit.get_cli_args"
3
4///|
5pub fn () -> Array[Bytes]
argv() -> type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[Bytes
Bytes] {
6 let FixedArray[Bytes]
argv = () -> FixedArray[Bytes]
moonbit_get_cli_args()
7 type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array::(Int, (Int) -> Bytes) -> Array[Bytes]
Creates a new array of the specified length, where each element is
initialized using an index-based initialization function.
Parameters:
length : The length of the new array. If length is less than or equal
to 0, returns an empty array.
initializer : A function that takes an index (starting from 0) and
returns a value of type T. This function is called for each index to
initialize the corresponding element.
Returns a new array of type Array[T] with the specified length, where each
element is initialized using the provided function.
Example:
test "Array::makei" {
let arr = Array::makei(3, fn(i) { i * 2 })
inspect(arr, content="[0, 2, 4]")
}
makei(FixedArray[Bytes]
argv.(self : FixedArray[Bytes]) -> Int
Returns the number of elements in a fixed-size array.
Parameters:
array : The fixed-size array whose length is to be determined.
Returns an integer representing the number of elements in the array.
Example:
test "FixedArray::length" {
let arr = FixedArray::make(3, 42)
inspect(arr.length(), content="3")
}
length(), fn(Int
i) { FixedArray[Bytes]
argv(FixedArray[Bytes], Int) -> Bytes
Retrieves an element at the specified index from a fixed-size array. This
function implements the array indexing operator [].
Parameters:
array : The fixed-size array to access.
index : The position in the array from which to retrieve the element.
Returns the element at the specified index.
Throws a runtime error if the index is out of bounds (negative or greater
than or equal to the length of the array).
Example:
test "FixedArray::op_get" {
let arr = FixedArray::make(3, 42)
inspect(arr[1], content="42")
}
test "panic FixedArray::op_get/out_of_bounds" {
let arr = FixedArray::make(3, 0)
ignore(arr[3]) // Index out of bounds
}
[i] })
8}
9
10///|
11pub fn () -> Array[String]
args() -> type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[String
String] {
12 let FixedArray[Bytes]
argv = () -> FixedArray[Bytes]
moonbit_get_cli_args()
13 let Array[String]
args = []
14 for Int
i in Int
0..<FixedArray[Bytes]
argv.(self : FixedArray[Bytes]) -> Int
Returns the number of elements in a fixed-size array.
Parameters:
array : The fixed-size array whose length is to be determined.
Returns an integer representing the number of elements in the array.
Example:
test "FixedArray::length" {
let arr = FixedArray::make(3, 42)
inspect(arr.length(), content="3")
}
length() {
15 Array[String]
args.(self : Array[String], value : String) -> Unit
Adds an element to the end of the array.
If the array is at capacity, it will be reallocated.
Example
let v = []
v.push(3)
push((encoding~ : @encoding.Encoding, input : @bytes.View) -> String
@encoding.decode_lossy(@encoding.Encoding
encoding=@encoding.Encoding
UTF8, FixedArray[Bytes]
argv(FixedArray[Bytes], Int) -> Bytes
Retrieves an element at the specified index from a fixed-size array. This
function implements the array indexing operator [].
Parameters:
array : The fixed-size array to access.
index : The position in the array from which to retrieve the element.
Returns the element at the specified index.
Throws a runtime error if the index is out of bounds (negative or greater
than or equal to the length of the array).
Example:
test "FixedArray::op_get" {
let arr = FixedArray::make(3, 42)
inspect(arr[1], content="42")
}
test "panic FixedArray::op_get/out_of_bounds" {
let arr = FixedArray::make(3, 0)
ignore(arr[3]) // Index out of bounds
}
[i]))
16 }
17 Array[String]
args
18}
19