range static method

FlowHandle range(
  1. Cell source, {
  2. required int start,
  3. required int count,
  4. int step = 1,
})

Emits a range of count integers starting from start on the first pulse received from source (Rx range).

range emits a sequence of integers starting from start and incrementing by step for count times.

When to use

Use range when you need to emit a numeric range.

  • Counters: Emitting counter values.
  • Indices: Emitting index sequences.
  • Test Data: Emitting numeric test data.
  • Loops: Emitting loop iteration values.
  • Paginations: Emitting page numbers.
  • ID Generation: Emitting sequential IDs.

How it works

  1. The first source pulse arms the instruction.
  2. Values are emitted starting from start.
  3. Each value increases by step.
  4. count values are emitted.
  5. Later pulses are ignored.
  6. Each emitted value gets the step 'Range' for provenance.

Parameters:

  • source: The Trigger Source. The cell that triggers the emission.
  • start: Starting Value. The first integer in the range.
  • count: Number of Values. How many integers to emit.
  • step: Step Size. The increment between values. Defaults to 1.

Returns:

A FlowHandle that can be used to observe the emitted values.

Example

final start = Cell.ingress<void>();

final handle = Flow.range(
  start.cell,
  start: 3,
  count: 5,
);

start.emit(null);
// Outputs: 3, 4, 5, 6, 7

Example: Range with Step

final handle = Flow.range(
  start.cell,
  start: 2,
  count: 5,
  step: 2,
);
// Outputs: 2, 4, 6, 8, 10

See Also:

  • of: For emitting fixed values.
  • fromIterable: For emitting from an iterable.
  • repeat: For emitting a repeated value.

Implementation

static FlowHandle range(
  Cell source, {
  required int start,
  required int count,
  int step = 1,
}) {
  return Range(start, count, step: step).toHandle(source: source);
}