Interface ListView<T>
A random-access CollectionView with numbered elements. Each entry has an index, ranging from 0
to count - 1, by which it can be accessed.
- See also:
-
ListWriter
List
- Source Code:
- View Source
Field Summary
enumeration :Iterator<(frost.core.Int, frost.collections.ListView.T)> - Returns an
Iteratorwhich returns(index, value)tuples. permutations :Iterator<ListView<T>> - An
Iteratorof all possible permutations of this list. powerSet :Iterator<ListView<T>> - Returns an
Iteratorwhich produces the elements of the power set of this list. last :T
Instance Method Summary
-- index operator --[] (index :):Int T - Returns an item from this list.
-- index operator --[] (r :):Range<Int> ListView<T> - Returns a slice of the list, containing all of the elements specified by the range.
-- index operator --[] (r :):Range<Int?> ListView<T> - Returns a slice of the list, containing all of the elements specified by the range.
-- index operator --[] (r :):SteppedRange<Int?, Int> ListView<T> - Returns a slice of the list, containing all of the elements specified by the range.
filter (predicate :):(T)=>(Bit) ListView<T> - Returns a new list containing every entry in this list for which the
predicatefunction returns true. filter (predicate :):(T)=&>(Bit) ListView<T> combine<U> (other :):ListView<U> ListView<(frost.collections.ListView.T, frost.collections.ListView.combine.U)> combine<U, V> (other :,ListView<U> f :):(T, U)=>(V) ListView<V> combine<U, V> (other :,ListView<U> f :):(T, U)=&>(V) ListView<V> combinations (n :):Int Iterator<ListView<T>> - Returns an
Iteratorof all possiblen-combinations of this list. sort (greater :):(T, T)=>(Bit) ListView<T> - Returns a sorted copy of the list using the provided comparison method.
map((T)=&>(U)):Array<U>map((T)=>(U)):Array<U>apply((T)=&>())fold((T, T)=&>(T), T):Tfold((T, T)=>(T), T):Tfold((T, T)=&>(T)):Tfold((T, T)=>(T)):Tjoin(String):Stringjoin():StringFields
Returns an Iterator which returns (index, value) tuples. For example,
["Hello", "Bonjour"].enumeration returns an Iterator<(Int, String)> which produces
(0, "Hello") followed by (1, "Bonjour").
An Iterator of all possible permutations of this list. A permutation is a distinct ordering;
each possible shuffling of a deck of cards is a different permutation. As the number of
permutations is equal to the factorial of the number of elements in the list, it is only
practical to fully iterate the permutations of very small lists (a list with just 15 elements in
it has over a trillion permutations).
Returns an Iterator which produces the elements of the power set of this list. The power set
of a list is the set of all possible subsets (including the empty list). For instance, the power
set of [1, 2, 3] is: [], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]. The iteration
order is not guaranteed.
As the power set of a list with n elements contains 2^n entries, iterating over the power set
is only practical for small lists.
Instance Methods
Returns an item from this list.
- Parameters:
-
-index the (zero-based) index of the item to return
-- index operator --
@default
@pre(r.min >= 0 & (r.inclusive & r.min < count | !r.inclusive & r.min <= count) &
r.max >= 0 & (r.inclusive & r.max < count | !r.inclusive & r.max <= count))
function []
(r :Range<Int>
):ListView<T>
Returns a slice of the list, containing all of the elements specified by the range. The slice is an independent copy of the list and elements may be added to and removed from the original without affecting the copy. It is not, however, a deep copy, and thus both lists will refer to the same objects.
- Parameters:
-
- value of typer Range<Int>
-- index operator --
@default
function []
(r :Range<Int?>
):ListView<T>
Returns a slice of the list, containing all of the elements specified by the range. The slice is an independent copy of the list and elements may be added to and removed from the original without affecting the copy. It is not, however, a deep copy, and thus both lists will refer to the same objects.
As usual for Range, a null min starts from the beginning of the list, and a null max ends
at the end of the list.
- Parameters:
-
- value of typer Range<Int?>
-- index operator --
@default
@pre(inRange(r, count))
function []
(r :SteppedRange<Int?, Int>
):ListView<T>
Returns a slice of the list, containing all of the elements specified by the range. The slice is an independent copy of the list and elements may be added to and removed from the original without affecting the copy. It is not, however, a deep copy, and thus both lists will refer to the same objects.
- Parameters:
-
- value of typer SteppedRange<Int?, Int>
@default
function filter
(predicate :(T)=>(Bit)
):ListView<T>
Returns a new list containing every entry in this list for which the predicate function
returns true. For instance, [1, 7, -10, 5, -2].filter(x => x > 0) returns [1, 7, 5].
- Parameters:
-
- value of typepredicate (T)=>(Bit)
@default
method filter
(predicate :(T)=&>(Bit)
):ListView<T>
- Parameters:
-
- value of typepredicate (T)=&>(Bit)
@default
@pre(count = other.count)
function combine<U>
(other :ListView<U>
):ListView<(frost.collections.ListView.T, frost.collections.ListView.combine.U)>
- Parameters:
-
- value of typeother ListView<U>
@default
@pre(count = other.count)
function combine<U, V>
(other :ListView<U> ,
f :(T, U)=>(V)
):ListView<V>
- Parameters:
-
- value of typeother ListView<U>
- value of typef (T, U)=>(V)
@default
@pre(count = other.count)
method combine<U, V>
(other :ListView<U> ,
f :(T, U)=&>(V)
):ListView<V>
- Parameters:
-
- value of typeother ListView<U>
- value of typef (T, U)=&>(V)
@default
@pre(count >= n)
function combinations
(n :Int
):Iterator<ListView<T>>
Returns an Iterator of all possible n-combinations of this list. An n-combination of a
list is a selection of n distinct elements from the list; the set of 5-combinations of a deck
of cards is the set of all possible poker hands. The combinations are chosen in such a way as to
preserve order: the combinations of a sorted list will themselves be sorted. Elements are
considered "distinct" if they appear at different positions in the input list. This means that
the 2-combinations of [1, 2, 2] are [1, 2], [1, 2], and [2, 2], as the two occurrences of 2
are considered distinct elements.
- Parameters:
-
- value of typen Int
- Returns:
- an iterator which produces the
n-combinations of this list
@default
method sort
(greater :(T, T)=>(Bit)
):ListView<T>
Returns a sorted copy of the list using the provided comparison method. The list is sorted so
that the greatest elements, according to the greater function, are at the end (higher indices)
of the array. The sort algorithm used may be unstable, meaning equal values (that is, values for
which greater(a, b) and greater(b, a) both return false) may be arbitrarily reordered
during the sort.
- Parameters:
-
- value of typegreater (T, T)=>(Bit)