# [Ride v5] List
⚠️ This is the documentation for the Standard library version 5. We recommend to use version 6. Go to version 6
List
is a list data type.
The list may contain elements of various types, including nested lists.
The maximim number of list items is 1000. The nesting depth is not limited. For weight restrictions, see the Data Weight article.
# List Operations
Lists support concatenation, as well as adding items to the beginning and the end.
Operation | Symbol | Complexity |
---|---|---|
Concatenation | ++ | 4 |
Adding the element to the end of the list (the list is on the left, the element is on the right) | :+ | 1 |
Adding the element to the beginning of the list (the element is on the left, the list is on the right) | :: | 2 |
# Examples
nil :+ 1 :+ 2 :+ 3
Result: [1, 2, 3]
1 :: 2 :: 3 :: nil
Result: [1, 2, 3]
let intList = [1, 2] # List[Int]
let strList = ["3", "4"] # List[String]
let joined = intList ++ strList # List[Int|String]
joined
Result: [1, 2, "3", "4"]
let appended = joined :+ true # List[Boolean|Int|String]
appended
Result: [1, 2, "3", "4", true]
let nested = intList :: joined # List[Int|List[Int]|String]
nested
Result: [[1, 2], 1, 2, "3", "4"]
# List Functions
The built-in list functions are presented in the List Functions article.
Operations on a list can be implemented via the FOLD<N> macro. The size of the list must be known in advance.
# List As Function Argument
A list, including nested one, can be a function argument:
func foo(arg: List[String|Unit]) = {
...
}
foo(["Ride","Waves",unit])
func bar(arg: List[List[Int]]) = {
...
}
bar([[1],[],[5,7]])
A callable function can take a list as an argument, but nested lists are not allowed:
@Callable(i)
func join(strings: List[String]) = {
[
StringEntry(toBase58String(i.caller.bytes), strings[0] + "_" + strings[1] + "_" + strings[2])
]
}
Invoke Script transaction example:
{
"type": 16,
...
"call": {
"function": "join",
"args": [
{
"type": "list",
"value": [
{
"type": "string",
"value": "alpha"
},
{
"type": "string",
"value": "beta"
},
{
"type": "string",
"value": "gamma"
}
]
}
]
},
...
}