Skip to content

Instantly share code, notes, and snippets.

@timathom
Last active March 21, 2016 13:41
Show Gist options
  • Save timathom/389d9ccba6412a840b8f to your computer and use it in GitHub Desktop.
Save timathom/389d9ccba6412a840b8f to your computer and use it in GitHub Desktop.
Anonymous inline function with asynchronous evaluation in BaseX
(:~
: Anonymous inline function with asynchronous evaluation in BaseX 8.4.1 beta
:
: @param $query Asynchronously evaluated query
: @return XQuery expression, followed by result of async HTTP request.
:
: BaseX Async Module:
: http://docs.basex.org/wiki/Async_Module
:
: Dimitre Novatchev on recursion with anonymous inline functions in XPath 3.0:
: https://dnovatchev.wordpress.com/2013/04/08/recursion-with-anonymous-inline-functions-in-xpath-3-0-part-ii/
:)
let $query := async:eval("http:send-request((), 'http://nytimes.com')")
let $f :=
function(
$q as xs:string,
$f1 as function(xs:string, function(*)) as item()*
) as item()* {
if (async:finished($q)) then (
<expr>{ 1 to 10 }</expr>, async:result($q)
)
else $f1($q, $f1)
}
let $F :=
function(
$q as xs:string
) as item()* {
<test>{ $f($q, $f) }</test>
}
return $F($query)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment