mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
95090fa4eb
### Why the changes in this PR are needed? Policies often need only the first or last few parts of a split string, but `split()` always returns every part. The common workarounds add noise: ```rego [name, email, _, _] := split(user, ";") [name, email] := array.slice(split(user, ";"), 0, 2) ``` ### What are the changes in this PR? Adds `strings.split_n(x, delimiter, n)`: - Positive n: returns the first n parts from the left - Negative n: returns the last abs(n) parts from the right - n=0: returns an empty array - If abs(n) exceeds the number of parts, all parts are returned ### Notes to assist PR review: Semantics follow the design agreed on in the review of #8361. ### Further comments: Fixes #8344 This change was developed with AI assistance. Signed-off-by: wonju lee <wonju@kia.com> Co-authored-by: wonju lee <wonju@kia.com>