-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
878 Add subsequence-where function #940
Conversation
There's a use case that this function doesn't handle especially well: "select all items that precede the first "X" if there is one, or all items up to the end otherwise". |
The CG agreed to merge this PR at meeting 062 |
Close #874 |
@michaelhkay I assigned »Blocked«, because a conflict must be resolved (due to one of my PRs, sorry). Regarding the pseudo-code, I noticed that the following query returns an empty sequence: let $input := 1 to 3
let $from := true#0
let $to := true#0
let $start := index-where($input, $from)[1] otherwise number('INF')
let $end := index-where($input, $to)[. ge $start][1] otherwise number('INF')
return subsequence($input, $start, ($end - $start)) Perhaps it would be more intuitive to return |
I think the informal description of the function is clear enough. Due to the quirky semantics of |
e6d862a
to
71c5e91
Compare
I have revised the PR (a) to remove conflicts, and (b) to take account of comments. The "formal" expansion of the function now relies on |
@michaelhkay I’m not sure if the version is correct. Examples: (: returns 6, 7, 8, 9, 10 ? :)
let $input := 1 to 10
let $from := fn { . = 5 }
let $to := fn { . = 5 }
let $start := index-where($input, $from)[1]
otherwise count($input) + 1
let $end := index-where($input, $to)[. ge $start][1]
otherwise count($input) + 1
return slice($input, $start, $end) (: returns 6, 7 ? :)
let $input := 1 to 10
let $from := fn { . = 5 }
let $to := fn { . = 6 }
let $start := index-where($input, $from)[1]
otherwise count($input) + 1
let $end := index-where($input, $to)[. ge $start][1]
otherwise count($input) + 1
return slice($input, $start, $end) If it’s correct, I should certainly spend more time on |
@ndw I wonder whether the |
Yes, open an issue. We agreed to merge this last week and I guess I was on autopilot. I'd have already merged it earlier if there hadn't been a conflict. |
Supersedes PR #874
Following discussion of PR #874 which proposed an extended subsequence() function with options to define the start and end position by predicates, this new PR proposes instead a subsequence-where() function that allows the start and end position to be defined by predicates, leaving the existing subsequence() function unchanged.
The items-before/after/starting-where/ending-where quartet are dropped.
The new function is inclusive at both ends. To start at the item after the one that matches the start condition, apply tail() to the result. To finish before the item that matches the end condition, apply trunk() to the result.