Overview of the functionalities

The itsample function allows to consume all the stream at once and return the sample collected:

using StreamSampling

st = 1:100;

itsample(st, 5)
5-element Vector{Int64}:
 15
 95
 69
 46
  6

In some cases, one needs to control the updates the ReservoirSampler will be subject to. In this case, you can simply use the fit! function to update the reservoir:

st = 1:100;

rs = ReservoirSampler{Int}(5);

for x in st
    fit!(rs, x)
end

value(rs)
5-element Vector{Int64}:
 43
 42
 60
 92
 26

If the total number of elements in the stream is known beforehand and the sampling is unweighted, it is also possible to iterate over a SequentialSampler like so

st = 1:100;

ss = SequentialSampler{Int}(st, 5, 100);

r = Int[];

for x in ss
    push!(r, x)
end

r
5-element Vector{Int64}:
  8
 18
 25
 44
 59

The advantage of SequentialSampler iterators in respect to ReservoirSampler is that they require O(1) memory if not collected, while reservoir techniques require O(k) memory where k is the number of elements in the sample.