marklogic invoke function with parameters
Asked Answered
L

1

6

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?

Leucippus answered 3/3, 2016 at 21:55 Comment(0)
D
9

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>)
Dali answered 3/3, 2016 at 22:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.