filter()
Pass through upstream values that satisfy a predicate.
Import
Section titled “Import”import { filter } from "@graphrefly/ts/operators";Signature
Section titled “Signature”function filter(pred: (v: S) => boolean): Operator<S, S>Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
pred | (v: S) => boolean | Predicate evaluated for each upstream DATA value. |
Returns
Section titled “Returns”An operator that emits matching values and stays quiet for non-matches.
Example
Section titled “Example”import { graph } from "@graphrefly/ts/graph";import { filter } from "@graphrefly/ts/operators";
const g = graph();const count = g.state(0);const even = g.initNode(filter((value: number) => value % 2 === 0), [count]);Source
Section titled “Source”packages/ts/src/graph/operators.ts