next up previous index
Next: Histograms Up: Advanced collection Previous: Keyed sets   Index

Collectors

In collector.diesel:

Sequences support the || concatenation operator. However, for long series of concatenations, using || many times can be inefficient and imply lots of copying. The collector extensible sequence data structure supports accumulating sequences for latter concatenation in one fell swoop.

Collectors can be created (optionally with a non-binding guess as to how many things will be collected together) using new_collector. The infix && operation is the more common way to construct collectors. Collectors are flattened into a vector form using flat_vector, and collectors of character sequences can be flattened into a simple string using flat_string. To illustrate the use of collectors versus concatenation:

    ("hi" && "there" && "bob").flat_string = "hi" || "there" || "bob"

extend module Stdlib;
module Collector;
class collector[T <= sequence_exactly[S]]
                                        isa ordered_collection_exactly[T];
  fun flat_string(:string|collector[string]):string;
  fun new_collector[T <= sequence_exactly[`S]]():collector[T];
fun &&(:(`T <= sequence_exactly[`S]) | collector[`T],
              :(`T <= sequence_exactly[`S]) | collector[`T]):collector[T];
end module Collector;


next up previous index
Next: Histograms Up: Advanced collection Previous: Keyed sets   Index

Cecil/Vortex Project