//! Lists (spec chapter 7, section 5).
module std.list
types {
/// An ordered, growable sequence.
pub intrinsic type List<T>
}
impl {
List<T> {
pub intrinsic fn new() -> List<T>
pub intrinsic fn len(self) -> Int
pub intrinsic fn is_empty(self) -> Bool
pub intrinsic fn push(mut self, own item: T)
pub intrinsic fn pop(mut self) -> Option<T>
pub intrinsic fn insert(mut self, index: Int, own item: T)
pub intrinsic fn remove(mut self, index: Int) -> T
pub intrinsic fn swap(mut self, i: Int, j: Int)
pub intrinsic fn reverse(mut self)
pub intrinsic fn clear(mut self)
pub intrinsic fn append(mut self, own other: List<T>)
pub intrinsic fn map<U>(self, f: fn(T) -> U) -> List<U>
pub intrinsic fn filter(own self, keep: fn(T) -> Bool) -> List<T>
pub intrinsic fn any(self, f: fn(T) -> Bool) -> Bool
pub intrinsic fn all(self, f: fn(T) -> Bool) -> Bool
pub intrinsic fn count(self, f: fn(T) -> Bool) -> Int
}
}
functions {
pub intrinsic fn contains<T: Equatable>(items: List<T>, item: T) -> Bool
pub intrinsic fn index_of<T: Equatable>(items: List<T>, item: T) -> Option<Int>
pub intrinsic fn get<T: Copyable>(items: List<T>, index: Int) -> Option<T>
/// Sorts in place; stable on every target.
pub intrinsic fn sort<T: Comparable>(mut items: List<T>)
/// Sorts in place with a comparison function; stable.
pub intrinsic fn sort_by<T>(mut items: List<T>, compare: fn(T, T) -> Ordering)
pub intrinsic fn min<T: Comparable + Copyable>(items: List<T>) -> Option<T>
pub intrinsic fn max<T: Comparable + Copyable>(items: List<T>) -> Option<T>
pub intrinsic fn sum(items: List<Int>) -> Int
/// `from..to` as a list.
pub intrinsic fn range(from: Int, to: Int) -> List<Int>
}