sampledFrom<T> function

Generator<T> sampledFrom<T>(
  1. List<T> values
)

Generates values picked from values.

The list is taken as it stands, so changing it afterwards does not change the generator. Values shrink toward the front of the list, which is worth knowing when writing one: put the ordinary case first and the exotic ones after it, and a counterexample will say which of them it needed.

Implementation

Generator<T> sampledFrom<T>(List<T> values) {
  if (values.isEmpty) {
    throw ArgumentError.value(
      values,
      'values',
      'is empty, and a generator has to be able to produce something',
    );
  }
  return _SampledGenerator<T>(List<T>.of(values));
}