fromIterable<T> method Null safety

Histogram fromIterable<T>(
  1. Iterable<T> entries,
  2. {required int sizeOf(
    1. T
    ),
  3. required String bucketFor(
    1. T
    ),
  4. required BucketInfo bucketInfo}
)

Implementation

static Histogram fromIterable<T>(
  Iterable<T> entries, {
  required int Function(T) sizeOf,
  required String Function(T) bucketFor,
  required BucketInfo bucketInfo,
}) {
  final buckets = <String, int>{};

  for (var e in entries) {
    final bucket = bucketFor(e);
    final size = sizeOf(e);
    buckets[bucket] = (buckets[bucket] ?? 0) + size;
  }

  return Histogram._(bucketInfo, buckets);
}