Interface CollectionWriter<T>
A write-only view of a collection of elements. CollectionWriter
provides methods to add and
remove elements, but not to retrieve them.
- See also:
-
CollectionView
Collection
ListWriter
- Source Code:
- View Source
Field Summary
Instance Method Summary
add (value :
)T - Adds a new element to the collection.
addAll (c :
)CollectionView<T> - Adds all elements in
c
to this collection. clear ()- Removes all elements in the collection.
filterInPlace (test :
)(T)=>(Bit) - Calls the
test
function on each element in the collection, removing all elements for which the function returnsfalse
. mapInPlace (f :
)(T)=>(T)
Fields
The number of elements in the collection.
Instance Methods
method add
(value :T
)
Adds a new element to the collection. The exact semantics of add
- does it add to the end of
the collection, or an arbitrary location? does it always actually add the element, or sometimes
leave the collection unmodified? - are defined by the collection implementation.
- Parameters:
-
- value of typevalue T
@default
method addAll
(c :CollectionView<T>
)
Adds all elements in c
to this collection. The default implementation simply calls add
for
each element in c
, in iteration order.
- Parameters:
-
- value of typec CollectionView<T>
@post(count = 0)
method clear
()
Removes all elements in the collection.
method filterInPlace
(test :(T)=>(Bit)
)
Calls the test
function on each element in the collection, removing all elements for which the
function returns false
.
For example, the code
def collection := [1, 2, 3, 4 ,5]
collection.filterInPlace(x => x % 2 = 1)
Console.printLine(collection)
will display [1, 3, 5]
, as the filter function returns true only for elements with odd values.
- Parameters:
-
- value of typetest (T)=>(Bit)
method mapInPlace
(f :(T)=>(T)
)
- Parameters:
-
- value of typef (T)=>(T)