Created
May 4, 2021 19:05
-
-
Save line-o/d4314b3464f4f2959853780c43672d12 to your computer and use it in GitHub Desktop.
distinct values from a given list in the order appearance
This file contains 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
xquery version "3.1"; | |
declare function local:distinct-order ($to-sort, $order) { | |
for $item in $to-sort[.=$order] | |
let $group-key := $item | |
group by $group-key | |
order by index-of($order, $group-key)[1] | |
return $group-key | |
}; | |
[ | |
local:distinct-order((2, 4, 5, 4, 6, 1, 2, 3), (1, 2, 3, 4, 5, 6)), | |
local:distinct-order((2, 4, 51, 4, 6, 111, 2, 3), (111, 2, 3, 4, 51, 6)) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment