This file contains 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
xquery version "3.0"; | |
declare function local:compose($f1 as function(item()) as item(), $f2 as function(item()) as item()) | |
as function(item()) as item() { | |
function($item) as item() { | |
$f2($f1($item)) | |
} | |
}; | |
(: 5 * x - 2 :) | |
let $linearFunction := | |
local:compose( | |
function($number) {$number * 5}, | |
function($number) {$number - 2}) | |
(: 3 * x^2 - 4 :) | |
let $quadraticFunction := | |
local:compose( | |
function($number) {$number * $number * 3}, | |
function($number) {$number - 4}) | |
return | |
<result> | |
<test1>{$linearFunction(5)} should equal 5 * 5 - 2 = 23</test1> | |
<test2>{$quadraticFunction(4)} should equal 3 * 4^2 - 4 = 44</test2> | |
</result> | |
(: | |
********************************************** | |
XQuery output: | |
********************************************** | |
<result> | |
<test1>23 should equal 5 * 5 - 2 = 23</test1> | |
<test2>44 should equal 3 * 4^2 - 4 = 44</test2> | |
</result> | |
:) |
No comments:
Post a Comment