Re: [xquery-talk] Purely recursive deduplication of sequence?

2020-08-01 Thread Christian Grün
> > 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

Re: [xquery-talk] Purely recursive deduplication of sequence?

2020-08-01 Thread Andreas Mixich
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

Re: [xquery-talk] Purely recursive deduplication of sequence?

2020-08-01 Thread Christian Grün
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

Re: [xquery-talk] Purely recursive deduplication of sequence?

2020-08-01 Thread Christian Grün
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: