>
> Of course, in the end, I am going to take the one, which has the
> best performance. Do you expect it to be the `FLOWR` based or
> the `fold-left#3` based, you demonstrated in the follow-up?
>
Solutions with fold-left are usually the most efficient ones, but it also
depends on the XQuery
Am 01.08.2020 um 14:57 schrieb Christian Grün:
Thank you so much for all three examples!
Of course, in the end, I am going to take the one, which has the
best performance. Do you expect it to be the `FLOWR` based or
the `fold-left#3` based, you demonstrated in the follow-up?
Still, I am glad to
Hi Andreas,
Try this:
declare function local:distinct-items($items as item()*) as item()* {
let $h := head($items)
where exists($h)
let $t := tail($items)[not(deep-equal(., $h))]
return ($h, local:distinct-items($t))
};
If the FLWOR expression is avoided, it may increase the runtime:
One more solution with fold-left (it’s faster than the recursive approach):
declare function local:distinct-items($items as item()*) as item()* {
fold-left($items, (), function($result, $item) {
$result, $item[empty($result[deep-equal(., $item)])]
})
};
local:distinct-items(('x', (1 to
Hello,
I wonder, whether it could be possible to deduplicate a sequence by a
purely recursive approach,
without creating state in any form.
What I have, so far, is only capable of removing consecutive dupes, so,
nothing fancy.
(:~
Removes all consecutive duplicate items from a sequence,