Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

marklogic invoke function with parameters

In the documentation for xdmp:invoke, it's possible to pass parameters as the second argument.

For xdmp:invoke-function this option is not available. Is there any workaround to achieve this?

Mapping a list to a function is easy. What I am trying to achieve is a kind of aspect oriented function which checks for what succeeded and failed and standard log messages for any functions that are called this way. Something like:

declare function my-mapper ($array, $fn) {
    (: standard logging and checks :)

    for $a in $array
    return try {
        (: now call the function with parameter :)
        xdmp:invoke-function($fn($a),<options>...</options>)

    } catch ($e) {
        (: standard housekeeping if something goes wrong :)      
        ...
    }
})


my-mapper($array, function ($item) {
     (: do stuff with item :)
})

Is there any way to achieve this in XQuery using MarkLogic?

like image 708
chriskelly Avatar asked Mar 03 '16 21:03

chriskelly


1 Answers

One executes a main module with no access to the context that called it, and the other executes a function with all that context. I think the idea is that you don't need to pass parameters through the invoke plumbing because you can pass them to the function as part of the call to xdmp:invoke-function. You would just need to wrap it in a 0-arity function:

xdmp:invoke-function(
  function () { $fn($a) },
  <options>...</options>)
like image 119
wst Avatar answered Oct 12 '22 15:10

wst