newListGenerate method

List<T> newListGenerate(
  1. int length,
  2. T function(
    1. int i
    ), {
  3. bool growable = false,
  4. bool reactive = true,
})

A method similar to the list constructor List.generate.

The method allocates the most performant list possible. For instance, Float32Kind, will give you a dart:typed_data Float32List rather than normal List<double> (if growable and reactive are false).

Example

import 'package:kind/kind.dart';

void main() {
  final kind = StringKind();
  final list = kind.newListFromGenerator(
    100,
    (i)=>'initial value',
    growable: false,
    reactive: false,
  );
}

Implementation

List<T> newListGenerate(
  int length,
  T Function(int i) function, {
  bool growable = false,
  bool reactive = true,
}) {
  final list = List<T>.generate(
    length,
    function,
    growable: growable,
  );
  if (reactive && (length != 0 || growable)) {
    return ReactiveList<T>.wrap(list);
  }
  return list;
}