Skip to content

fastflowtransform.cli.selectors

augment_with_state_modified

augment_with_state_modified(tokens, base_pred, modified)

Combine a base predicate with state:modified tokens. - 'state:modified' → filter to modified only - 'state:modified+' → filter to modified union downstream(modified) - Combined with other tokens → logical AND with base predicate

Source code in src/fastflowtransform/cli/selectors.py
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
def augment_with_state_modified(
    tokens: list[str],
    base_pred: Callable[[Any], bool],
    modified: set[str],
) -> Callable[[Any], bool]:
    """
    Combine a base predicate with state:modified tokens.
    - 'state:modified'    → filter to modified only
    - 'state:modified+'   → filter to modified union downstream(modified)
    - Combined with other tokens → logical AND with base predicate
    """
    if not any(t.startswith("state:modified") for t in tokens):
        return base_pred

    plus = any(t.startswith("state:modified+") for t in tokens)
    state_set = set(modified)
    if plus:
        state_set = _downstream_closure(state_set)

    other_tokens = [t for t in tokens if not t.startswith("state:modified")]
    if not other_tokens:
        return lambda n: n.name in state_set
    return lambda n: (n.name in state_set) and base_pred(n)