data List
Dynamic array (§3.3). [a, b] literals have this type.
Example:
fn main() io {
var xs = [3, 1, 2]
xs.push(0)
xs.sort()
print("{xs} first={xs[0]} len={xs.len()}")
}Вывод
[0, 1, 2, 3] first=0 len=4
@builtin("List") pub(api) data List<T>Сложность. indexing and `push` O(1) (amortized), `insert`/`remove` O(n), `contains` O(n), `sort` O(n log n).
Потокобезопасность. not shared between tasks; send a copy (or a `frozen` list) to another task.
С версии. 1.0.0-beta
Методы
new | () -> SelfEmpty list. |
len | () -> usizeNumber of elements. |
isEmpty | () -> boolWhether the list has no elements. |
push | (x: T)Appends an element. |
pop | () -> T?Removes and returns the last element. |
get | (i: usize) -> T?Element at i or none. |
insert | (i: usize, x: T)Inserts x before the element at index i; later elements move one place up. |
remove | (i: usize) -> TRemoves and returns the element at index i; later elements move one place down. |
clear | ()Removes all elements. |
contains | (x: T) -> boolWhether some element equals x. |
reverse | ()Reverses the order of the elements in place. |
sort | ()Stable sort by the natural order (Ord). |
clone | () -> List<T>A copy of the list (elements are cloned too). |
first | () -> T?The first element, or none for an empty list. |
last | () -> T?The last element or none. |
map | (f: fn(T) -> U F) -> List<U> FA new list with f applied to every element. |
filter | (p: fn(T) -> bool F) -> List<T> FA new list with the elements for which p is true. |
fold | (start: A, f: fn(A, T) -> A F) -> A FFolds the list from the left |
any | (p: fn(T) -> bool F) -> bool FTrue when p holds for at least one element. |
all | (p: fn(T) -> bool F) -> bool FTrue when p holds for every element. |
count | (p: fn(T) -> bool F) -> usize FThe number of elements for which p is true. |
enumerate | () -> List<(usize, T)>Pairs every element with its index. |
forEach | (f: fn(T) F)Calls f for every element. |
iter | () -> iter<T>Lazy iterator over a snapshot of the list (D-2001) |
intoIter | () -> iter<T>Lazy iterator that takes the list over (no copy). |
sum | () -> i64The sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> i64The product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> i64?The smallest element, or none for an empty list. |
max | () -> i64?The largest element, or none for an empty list. |
sum | () -> i32The sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> i32The product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> i32?The smallest element, or none for an empty list. |
max | () -> i32?The largest element, or none for an empty list. |
sum | () -> i16The sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> i16The product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> i16?The smallest element, or none for an empty list. |
max | () -> i16?The largest element, or none for an empty list. |
sum | () -> i8The sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> i8The product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> i8?The smallest element, or none for an empty list. |
max | () -> i8?The largest element, or none for an empty list. |
sum | () -> isizeThe sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> isizeThe product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> isize?The smallest element, or none for an empty list. |
max | () -> isize?The largest element, or none for an empty list. |
sum | () -> i128The sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> i128The product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> i128?The smallest element, or none for an empty list. |
max | () -> i128?The largest element, or none for an empty list. |
sum | () -> u64The sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> u64The product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> u64?The smallest element, or none for an empty list. |
max | () -> u64?The largest element, or none for an empty list. |
sum | () -> u32The sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> u32The product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> u32?The smallest element, or none for an empty list. |
max | () -> u32?The largest element, or none for an empty list. |
sum | () -> u16The sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> u16The product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> u16?The smallest element, or none for an empty list. |
max | () -> u16?The largest element, or none for an empty list. |
sum | () -> u8The sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> u8The product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> u8?The smallest element, or none for an empty list. |
max | () -> u8?The largest element, or none for an empty list. |
sum | () -> usizeThe sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> usizeThe product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> usize?The smallest element, or none for an empty list. |
max | () -> usize?The largest element, or none for an empty list. |
sum | () -> u128The sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> u128The product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> u128?The smallest element, or none for an empty list. |
max | () -> u128?The largest element, or none for an empty list. |
sum | () -> f64The sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> f64The product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> f64?The smallest element, or none for an empty list. |
max | () -> f64?The largest element, or none for an empty list. |
sum | () -> f32The sum of the elements (0 for an empty list); panics on overflow like +. |
product | () -> f32The product of the elements (1 for an empty list); panics on overflow like *. |
min | () -> f32?The smallest element, or none for an empty list. |
max | () -> f32?The largest element, or none for an empty list. |
join | (sep: str) -> strConcatenation of the elements separated by sep. |
sortBy | (key: fn(T) -> K)Stable sort by the natural order of key(x). |
Определено в: std/core/types.oxl:25
См. также
- std.core
- List.new
- List.len
- List.isEmpty
- List.push
- List.pop
- List.get
- List.insert
- List.remove
- List.clear
- List.contains
- List.reverse
- List.sort
- List.clone
- List.first
- List.last
- List.map
- List.filter
- List.fold
- List.any
- List.all
- List.count
- List.enumerate
- List.forEach
- List.iter
- List.intoIter
- List.sum
- List.product
- List.min
- List.max
- List.sum
- List.product
- List.min
- List.max
- List.sum
- List.product
- List.min
- List.max
- List.sum
- List.product
- List.min
- List.max
- List.sum
- List.product
- List.min
- List.max
- List.sum
- List.product
- List.min
- List.max
- List.sum
- List.product
- List.min
- List.max
- List.sum
- List.product
- List.min
- List.max
- List.sum
- List.product
- List.min
- List.max
- List.sum
- List.product
- List.min
- List.max
- List.sum
- List.product
- List.min
- List.max
- List.sum
- List.product
- List.min
- List.max
- List.sum
- List.product
- List.min
- List.max
- List.sum
- List.product
- List.min
- List.max
- List.join
- List.sortBy