Language Reference: Lists
null
Important list-related functions include:
| Function | Use |
|---|---|
| drop | Remove values from the start of a list |
| isEmpty | Check if a list is empty |
| len | Get the length of a list |
| push | Add a value to the end of a list |
| range | Get a list of integers up to a value |
| reverse | Reverse a list |
| sort | Sort a list in ascending order |
| sortDesc | Sort a list in descending order |
| span | Get a list of integers between two values |
| take | Get values from the front of a list |
See the standard library List module for more built-in functions for working with lists.
Lists
states = ["CT", "MA", "ME", "NH", "RI", "VT"]
states =["CT", "MA", "ME", "NH", "RI", "VT"]
states[0]
states[1]
"CT"
"MA"
states[-1]
states[-2]
"VT"
"RI"
states[1] = "Massocheichei"
states[-1] += "!"
states =["CT", "Massocheichei", "ME", "NH", "RI", "VT!"]
Map Operator
["Jan", "Feb", "Mar", "Apr", "May", "June"] $ Str.toUpper
span(0, 10) $ 2 ** arg
["JAN", "FEB", "MAR", "APR", "MAY", "JUNE"]
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]
Filter Operator
["Jan", "Feb", "Mar", "Apr", "May", "June"] ? Str.startsWith("J")
span(0, 10) ? Math.isOdd
["Jan", "June"]
[1, 3, 5, 7, 9]
Concatenation
["Jan", "Feb", "Mar"] + ["Apr", "May", "June"]
["Jan", "Feb", "Mar", "Apr", "May", "June"]
Repetition
[0] * 5
["do", "re", "mi"] * 2
[0, 0, 0, 0, 0]
["do", "re", "mi", "do", "re", "mi"]