@@ -2876,6 +2876,46 @@ export class MapElementsStep<TInput> extends Step<MapElementsStepConfig<TInput>>
28762876 }
28772877}
28782878
2879+ export interface FilterPredicateStepConfig < TInput > extends StepConfig {
2880+ /**
2881+ * The predicate used to decide whether to keep each element.
2882+ */
2883+ predicate : ( value : TInput ) => boolean ;
2884+ }
2885+
2886+ export class FilterPredicateStep < TInput > extends Step < FilterPredicateStepConfig < TInput > > {
2887+ public get name ( ) {
2888+ return "FilterPredicate" ;
2889+ }
2890+
2891+ public * traverse (
2892+ _source : GraphSource < any > ,
2893+ input : Iterable < TInput > ,
2894+ _context ?: QueryContext ,
2895+ ) : IterableIterator < unknown > {
2896+ const { predicate } = this . config ;
2897+ for ( const value of input ) {
2898+ this . traversed ++ ;
2899+ if ( predicate ( value as TInput ) ) {
2900+ this . emitted ++ ;
2901+ yield value ;
2902+ }
2903+ }
2904+ }
2905+
2906+ public override clone ( partial ?: Partial < FilterPredicateStepConfig < TInput > > ) {
2907+ const { config } = this ;
2908+ return new FilterPredicateStep ( {
2909+ predicate : partial ?. predicate ?? config . predicate ,
2910+ stepLabels : partial ?. stepLabels ?? ( config . stepLabels ? [ ...config . stepLabels ] : undefined ) ,
2911+ } ) ;
2912+ }
2913+
2914+ public override toJSON ( ) : [ string , FilterPredicateStepConfig < TInput > , unknown ?] {
2915+ throw new Error ( "Cannot convert FilterPredicateStep to JSON." ) ;
2916+ }
2917+ }
2918+
28792919export interface GroupByStepConfig extends StepConfig {
28802920 /**
28812921 * The items to group by (variable, property, function like labels/type).
@@ -7360,6 +7400,7 @@ const KnownSteps = {
73607400 Unwind : UnwindStep ,
73617401 Call : CallStep ,
73627402 MapElements : MapElementsStep ,
7403+ FilterPredicate : FilterPredicateStep ,
73637404 Range : RangeStep ,
73647405 Order : OrderStep ,
73657406 FilterElements : FilterElementsStep ,
@@ -7394,6 +7435,7 @@ export type KnownSteps =
73947435 | RepeatStep < any >
73957436 | DedupStep
73967437 | MapElementsStep < any >
7438+ | FilterPredicateStep < any >
73977439 | RangeStep
73987440 | OrderStep
73997441 | SumStep
0 commit comments