BoolList.generate constructor

BoolList.generate(
  1. int length,
  2. bool generator(
    1. int
    ), {
  3. bool growable = true,
})

Generates a BoolList of values.

Creates a BoolList with length positions and fills it with values created by calling generator for each index in the range 0 .. length - 1 in increasing order.

The created list is fixed-length unless growable is true.

Implementation

factory BoolList.generate(
  int length,
  bool Function(int) generator, {
  bool growable = true,
}) {
  RangeError.checkNotNegative(length, 'length');

  var instance = BoolList._selectType(length, growable);
  for (var i = 0; i < length; i++) {
    instance._setBit(i, generator(i));
  }
  return instance;
}