Interface CollectionView<T>
A read-only view of a collection of elements. A CollectionView
's elements are accessed via its
iterator
property.
- See also:
-
CollectionWriter
Collection
ListView
- Source Code:
- View Source
Field Summary
count :Int - The number of elements in the collection.
first :T - Returns the first element in the collection in iteration order.
Instance Method Summary
join ():String - Returns the string concatenation of all of the items in this collection, in iteration order.
join (separator :
):String String - Converts all of the items in this collection to strings and concatenates them in iteration order, with the given separator between them.
fold (f :
):(T, T)=>(T) T - Successively applies a binary function to 'fold' the elements in the list down to a single value.
fold (f :
):(T, T)=&>(T) T - As
fold((T, T)=>(T))
, but for methods instead of functions. fold (f :
,(T, T)=>(T) start :
):T T - As
fold((T, T)=>(T))
, but additionally takes a starting value for the fold operation. fold (f :
,(T, T)=&>(T) start :
):T T - As
fold((T, T)=>(T), T)
, but for methods instead of functions. apply (m :
)(T)=&>() - Calls the method
m
on each element of the collection in iteration order. map<U> (f :
):(T)=>(U) Array<U> - Returns an array containing the result of calling
f
on every element in this collection. map<U> (f :
):(T)=&>(U) Array<U> - As
map((T)=>(U))
, but for methods instead of functions.
Fields
The number of elements in the collection.
Returns the first element in the collection in iteration order.
Instance Methods
@default
function join
():String
Returns the string concatenation of all of the items in this collection, in iteration order.
Equivalent to join("")
.
- See also:
-
join(String)
Converts all of the items in this collection to strings and concatenates them in iteration
order, with the given separator between them. For instance, [1, 2, 3].join("|")
returns
"1|2|3"
.
- Parameters:
-
-separator the delimiter string
- See also:
-
join()
@default
@pre(count > 0)
function fold
(f :(T, T)=>(T)
):T
Successively applies a binary function to 'fold' the elements in the list down to a single
value. For instance, if we have a collection of Int64
s and fold using the binary function
Int64.+(Int64)
, as in:
[1, 2, 3, 4, 5].fold(Int.+)
this would add the first (in iteration order) and second elements of the collection together, and then add the sum of the first two elements to the third, and so forth until all of the elements of the collection had been added together. This would result in the sum of all of the elements in the collection.
Similarly, we could fold using Int64.max(Int64)
to find the biggest number in the list,
Int64.*(Int64)
to get the product of all of the numbers in the list, etc.
If the list has only a single element in the list, the result of fold
is this single element
and the function f
is never called. This variant of fold
may not be called on an empty list
because the result would be undefined.
- Parameters:
-
-f a binary function to combine elements of the collection
- Returns:
- the result of combining the entire collection
- See also:
-
fold((T, T)=>(T), T)
@default
@pre(count > 0)
method fold
(f :(T, T)=&>(T)
):T
As fold((T, T)=>(T))
, but for methods instead of functions.
- Parameters:
-
- value of typef (T, T)=&>(T)
As fold((T, T)=>(T))
, but additionally takes a starting value for the fold operation. The
starting value is folded into the first element of the list, the result is then folded into the
second element, etc. This allows fold
to be well-defined even on an empty list: folding an
empty list simply returns the start value.
- Parameters:
-
-f a binary function to combine elements of the collection
-start the starting value for the fold
- See also:
-
fold((T, T)=>(T))
As fold((T, T)=>(T), T)
, but for methods instead of functions.
- Parameters:
-
- value of typef (T, T)=&>(T)
- value of typestart T
@default
method apply
(m :(T)=&>()
)
Calls the method m
on each element of the collection in iteration order. For instance, to
display every element in a collection you could write:
collection.apply(Console.printLine)
- Parameters:
-
-m a method to call on each element
@default
function map<U>
(f :(T)=>(U)
):Array<U>
Returns an array containing the result of calling f
on every element in this collection. For
example,
Console.printLine(Int[1 ... 5].map(2.*))
applies the function 2.*
to the integers from 1 to 5. This displays [2, 4, 6, 8, 10]
.
- Parameters:
-
- value of typef (T)=>(U)
@default
method map<U>
(f :(T)=&>(U)
):Array<U>
As map((T)=>(U))
, but for methods instead of functions.
- Parameters:
-
- value of typef (T)=&>(U)