Created
January 15, 2013 07:21
-
-
Save nine9ths/4536886 to your computer and use it in GitHub Desktop.
XPath 3.0 recursion with inline function and partial function application, adapted from http://www.xfront.com/Pearls-of-XSLT-and-XPath-3-0-Design.pdf and http://dnovatchev.wordpress.com/2012/10/15/recursion-with-anonymous-inline-functions-in-xpath-3-0-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
let | |
$isNegative := function($x as xs:integer) {$x lt 0}, | |
$decrement := function($x as xs:integer) {$x - 1}, | |
$until.r := | |
function( | |
$p as function(item()*) as xs:boolean, | |
$f as function(item()*) as item()*, | |
$x as item()*, | |
$r as function(function(), function(), item()*, function()) as item()*) as item()* { | |
if ($p($x)) then $x else $helper($p, $f, $f($x), $r) | |
}, | |
$until := | |
$helper(?,?,?,$until.r) | |
return $until($isNegative, $decrement, 20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment