intStream static method

IntStream intStream(
  1. Iterable<int> source, {
  2. bool parallel = false,
})

Creates a new sequential or parallel IntStream from an Iterable of integers.

Parameters

  • source: The iterable of integers to create a stream from
  • parallel: Whether the stream should be parallel (default: false)

Example

final numbers = [1, 2, 3, 4, 5];
final intStream = StreamSupport.intStream(numbers);
final parallelIntStream = StreamSupport.intStream(numbers, parallel: true);

A sequence of primitive int-valued elements supporting sequential and parallel aggregate operations.

This is the int primitive specialization of BaseStream. It supports fluent-style functional operations such as map, filter, reduce, and terminal operations for processing or collecting data.

Example Usage

// Create an IntStream from a range
final sum = IntStream.range(1, 10)
    .filter((n) => n % 2 == 0)
    .sum();
print(sum); // 20

// Statistical operations
final stats = IntStream.of([1, 2, 3, 4, 5])
    .summaryStatistics();
print('Average: ${stats.average}');
print('Max: ${stats.max}');

// Complex transformations
final result = IntStream.range(1, 100)
    .filter((n) => n % 3 == 0)
    .map((n) => n * n)
    .limit(5)
    .toList();

Implementation

static IntStream intStream(Iterable<int> source, {bool parallel = false}) {
  final stream = IntStream.of(source);
  return parallel ? stream.parallel() : stream;
}