partitionOnly<S> static method

FlowHandle partitionOnly<S>(
  1. Cell source, {
  2. required bool test(
    1. S value
    ),
  3. bool matched = true,
  4. PartitionErrorHandler? onError,
})

Keep only the matching side.

partitionOnly is a filtering operator that only passes values that match the predicate.

When to use

Use partitionOnly when you only want values that match (or don't match) a predicate.

  • Filtering: Filtering values by a condition.
  • Positive Filtering: Keeping only matching values.
  • Negative Filtering: Keeping only non-matching values.
  • Validation: Passing only valid values.
  • Data Cleaning: Keeping only clean data.

How it works

  1. Each incoming pulse is type-checked.
  2. If the type matches, test is called with the payload.
  3. If test returns matched (default true), the value is emitted.
  4. If test returns the opposite, the value is dropped.
  5. If test throws an error, the pulse is dropped.

Parameters:

  • source: The Source Cell. The cell providing the input values.
  • test: Predicate Function. Called with each typed payload, returns true for values to be considered.
  • matched: Filter Mode. If true, keeps values where test returns true. If false, keeps values where test returns false. Defaults to true.
  • onError: Error Handler. Optional callback for handling errors.

Type Parameters:

  • S: The type of the input payload.

Returns:

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

Example

final input = Cell.ingress<int>();

final handle = Flow.partitionOnly<int>(
  input.cell,
  test: (n) => n.isEven,
);

input.emit(1); // dropped
input.emit(2); // -> 2
input.emit(3); // dropped
input.emit(4); // -> 4

See Also:

  • partition: For tagging values with match status.
  • partitionMap: For mapping matched/unmatched values differently.

Implementation

static FlowHandle partitionOnly<S>(
  Cell source, {
  required bool Function(S value) test,
  bool matched = true,
  PartitionErrorHandler? onError,
}) {
  return PartitionOnly<S>(
    test,
    matched: matched,
    onError: onError,
  ).toHandle(source: source);
}