Add rc.slice custom operator - #7505
Open
ajpallares wants to merge 13 commits into
Open
Conversation
Takes a run of elements out of an array, with the start and length semantics substr already uses for strings. Pairs with rc.sortBy to express top-N without a reduce carrying a compound accumulator. Co-authored-by: Cursor <cursoragent@cursor.com>
The tenth operator pushed the switch past the limit. Operators.dispatch carries the same exemption for the same reason. Co-authored-by: Cursor <cursoragent@cursor.com>
…ngine-rc-slice Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # Tests/UnitTests/RulesEngine/PredicateFixtureTests.swift
…ngine-rc-slice Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # Tests/UnitTests/RulesEngine/PredicateFixtureTests.swift
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2 tasks
…ngine-rc-slice Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # Tests/UnitTests/RulesEngine/PredicateFixtureTests.swift
tonidero
approved these changes
Aug 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Checklist
purchases-androidand hybridsMotivation
Keeping a run of an array has no operator: it composes from
rc.entries+filter+map, but the index arrives as a string and negative-index clamping is hand-written, so simple filters like "the last three events" can be really hard to express and read.Description
{"rc.slice": [array, start]}or{"rc.slice": [array, start, length]}.substr: negative start counts from the end, negative length drops from the right, and both clamp instead of failing. The third argument is therefore a count, not an end index — deliberatelysubstr's convention rather than JSslice's, so the engine has one indexing model.substr..floatis accepted since all arithmetic returns it, solength - 1works; fractional or non-numeric throws instead of being truncated or coerced assubstrdoes.Note
Low Risk
Isolated new Rules Engine operator with broad fixture coverage; no changes to existing operator behavior beyond the dispatch switch.
Overview
Adds
rc.sliceso JSON Logic rules can take a contiguous run from an array without composingrc.entries+ filter/map workarounds.{"rc.slice": [array, start]}or with an optionallengththird argument. Indexing follows existingsubstrrules: negativestartis from the end, negativelengthtrims from the right, out-of-range values clamp instead of erroring, and the third arg is a count (not a JS-style end index). Only arrays are accepted—strings still usesubstr, with a hint in the error. Start/length must be whole numbers; whole-valued floats from arithmetic are allowed, but fractional or coerced values throwtypeMismatch(stricter thansubstr).Wired through
CustomOperators.dispatch, added to the Xcode target, and covered byrc_slice.jsonpredicate fixtures (fixture total 544 → 578).Reviewed by Cursor Bugbot for commit ec948ab. Bugbot is set up for automated code reviews on this repo. Configure here.