Files
purchases-ios/Sources/RulesEngine/CustomOperators
Antonio PallaresandCursor 4bd110f723 Add rc.sortBy custom operator (#7504)
* Add rc.sortBy custom operator

Orders an array by a key computed per item, ascending, with ties keeping
their input order. Keys must be all strings or all numbers so the two
engines never have to invent a cross-type ordering.

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

* Reject non-finite rc.sortBy keys

A NaN key compares false in both directions, so every pair tied and the
input came back unsorted with no error. Negating a string key to attempt
a descending sort produced exactly that.

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

* Note ascending order in the rc.sortBy summary

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

* Trim the rc.sortBy doc comment

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

* Trim the rc.sortBy stability comment

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

* Order rc.sortBy string keys by UTF-16 code unit

Swift's < orders by Unicode scalar and treats canonically equivalent
strings as equal, while JS and Kotlin order by UTF-16 code unit. The two
disagree once a scalar above the surrogate range meets an astral one, so
the same rule would sort differently on iOS and Android.

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

* Keep the rc.sortBy ordering fixtures platform-neutral

The fixture files are byte-identical across the iOS and Android engines, so
a description that explains the contract in terms of one host language's
string comparison does not read correctly in the other repository.

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

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-31 08:10:18 +02:00
..