Skip to content

Add rc.let custom operator - #7506

Draft
ajpallares wants to merge 11 commits into
pallares/rules-engine-rc-slicefrom
pallares/rules-engine-rc-let
Draft

Add rc.let custom operator#7506
ajpallares wants to merge 11 commits into
pallares/rules-engine-rc-slicefrom
pallares/rules-engine-rc-let

Conversation

@ajpallares

@ajpallares ajpallares commented Aug 25, 2026

Copy link
Copy Markdown
Member

Checklist

  • If applicable, unit tests
  • If applicable, create follow-up issues for purchases-android and hybrids

Motivation

Iteration replaces the whole scope with the current item, so a predicate inside some or reduce cannot reach a value from the enclosing level, which is what ranking, deduplication and "this item versus the others" all need. rc.rootVar only reaches the root, not intermediate levels.

Description

{"rc.let": [{"name": expression, ...}, body]} evaluates body with each name available to var, and the names survive scope rebinding.

  • var reads the active data first, bindings second. A binding therefore cannot mask a field the data has, and any predicate without an rc.let around it resolves exactly as before, including missing, which agrees with var on what exists.
  • Declarations all evaluate in the enclosing scope, so bindings cannot see each other and their order carries no meaning. Nest a second rc.let to chain them.
  • The declaration object is deliberately never evaluated as a whole, since a single-key object anywhere else is an operator call. Names must be non-empty and free of ..

Binds names that survive iteration, so a nested predicate can compare an
item against a value from the enclosing level. var reads the active data
first and falls back to bindings, leaving predicates without an rc.let
resolving exactly as before.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ajpallares ajpallares added pr:feat A new feature pr:other feat:Checkpoints and removed pr:feat A new feature labels Aug 25, 2026
…ine-rc-let

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	Tests/UnitTests/RulesEngine/PredicateFixtureTests.swift
…ine-rc-let

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	Tests/UnitTests/RulesEngine/PredicateFixtureTests.swift
…ine-rc-let

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	Tests/UnitTests/RulesEngine/PredicateFixtureTests.swift
…ine-rc-let

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	Tests/UnitTests/RulesEngine/PredicateFixtureTests.swift
…ine-rc-let

Co-authored-by: Cursor <cursoragent@cursor.com>

# Conflicts:
#	Tests/UnitTests/RulesEngine/PredicateFixtureTests.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant