Loading TOC...

xdmp.apply

xdmp.apply(
   function as function,
   [params-1-to-N as Sequence]
) as Sequence

Summary

Applies an xdmp:function with the given parameters.

Parameters
function The xdmp:function value to be applied.
params-1-to-N The parameters to pass into the specified function value. Specify one parameter for each parameter that the specified function takes, with the first parameter corresponding to the first parameter in the specified function's signature, the second parameter corresponding to the second, and so on. Omit this parameter if the specified function takes no parameters.

Example

var f = xdmp.function(xs.QName("fn:empty"));
xdmp.apply(f, []);

  => true

Example

var f = xdmp.function(xs.QName("fn:concat"));
xdmp.apply(f, "hello", " world");

=> hello world

Example

Given square.sjs in the modules database as the following:

module.exports = function(width) {
  return {
    area: function() {
      return width * width;
    },
    set: function(_width) {
      width = _width;
    }
  };
}

var mySquare = fn.head(xdmp.apply(xdmp.function(null,"square.sjs"),4));
xdmp.apply(mySquare.set, 3);
xdmp.apply(mySquare.area)

=> 9

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.