Skip to content

Instantly share code, notes, and snippets.

@nine9ths
Created January 15, 2013 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nine9ths/4536886 to your computer and use it in GitHub Desktop.
Save nine9ths/4536886 to your computer and use it in GitHub Desktop.
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