This file contains hidden or 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
{{ revealedCharacter }}
| 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 | |
| }; |
This file contains hidden or 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
{{ revealedCharacter }}
| xquery version "3.1"; | |
| declare namespace dicey="http://line-o.de/ns/dicey"; | |
| declare function dicey:sequence ($n as xs:integer, | |
| $generator as map(xs:string, item())) as item()* { | |
| fold-left( | |
| 1 to $n, | |
| map { "sequence": (), "generator": $generator}, | |
| dicey:reducer#2 |
This file contains hidden or 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
{{ revealedCharacter }}
| xquery version "3.1"; | |
| module namespace qs="http://line-o.de/ns/qs"; | |
| (:~ | |
| : Append nothing to names of parameters with multiple values | |
| : ?single=v1&multi=v2&multi=v3 | |
| :) |
This file contains hidden or 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
{{ revealedCharacter }}
| xquery version "3.1"; | |
| map { | |
| "date" : current-dateTime(), | |
| "packages" : array { | |
| for $get-package-event in collection("/db/apps/public-repo-data/logs")//type[.="get-package"]/.. | |
| group by $name := $get-package-event/package-name/string() | |
| let $event-count := count($get-package-event) | |
| order by $event-count descending | |
| return |
This file contains hidden or 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
{{ revealedCharacter }}
| xquery version "3.1"; | |
| declare variable $local:millisecond := xs:dayTimeDuration('PT0.001S'); | |
| declare variable $local:max := 3000; | |
| declare variable $local:reference := for-each(1 to $local:max, xs:string(?)); | |
| declare variable $local:test := for-each((3 to 400, 402 to 2900), xs:string(?)); | |
| declare function local:one () { | |
| let $as-map := |
This file contains hidden or 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
{{ revealedCharacter }}
| xquery version "3.1"; | |
| (: adapted from https://stackoverflow.com/a/4936099 :) | |
| declare function local:fib-reducer ($r, $n) { $r[1] + $r[2], $r[1] }; | |
| declare function local:fib($n as xs:integer) { | |
| fold-left((1 to $n), (0,1), local:fib-reducer#2)[1] | |
| }; | |
| let $results := |
This file contains hidden or 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
{{ revealedCharacter }}
| xquery version "3.1"; | |
| import module namespace xbow="http://line-o.de/xq/xbow"; | |
| let $length := 100000 | |
| let $sequence-of-maps := (1 to $length) ! map { "n": ., "values": ("a" || util:random(100), "b" || util:random(100), "c" || util:random(100)) } | |
| let $keyed-sequence := |
This file contains hidden or 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
{{ revealedCharacter }}
| xquery version "3.1"; | |
| declare | |
| function local:find($path, $document-id as xs:integer) as xs:string* { | |
| local:find-in-collection($path, (), $document-id) | |
| }; | |
| declare | |
| function local:resource ($collection as xs:string, $resource as xs:string, $document-id as xs:integer) as xs:string? { | |
| let $path := $collection || '/' || $resource |
This file contains hidden or 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
{{ revealedCharacter }}
| xquery version "3.1"; | |
| import module namespace xbow = "http://line-o.de/xq/xbow"; | |
| declare namespace xqdoc="http://www.xqdoc.org/1.0"; | |
| declare variable $local:length-category-rules := [ | |
| xbow:le(2), xbow:le(4), xbow:le(8), xbow:le(12), xbow:gt(12) ]; | |
| declare function local:gather-and-count ($names) { | |
| $names |
This file contains hidden or 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
{{ revealedCharacter }}
| xquery version "3.1"; | |
| declare function local:random-number () { | |
| util:random(1000000000) div 1000000000 | |
| }; | |
| declare function local:random-number-generator () { | |
| map { | |
| 'number': local:random-number(), | |
| 'next': local:random-number-generator#0, |