jsonata-js / jsonata

JSONata query and transformation language - http://jsonata.org
MIT License
2.05k stars 220 forks source link

varargs parameter signature #711

Open alturkovic opened 2 weeks ago

alturkovic commented 2 weeks ago

There is currently support for the following:

    + - one or more arguments of this type
        E.g. $zip has signature <a+>; it accepts one array, or two arrays, or three arrays, or...
    ? - optional argument
        E.g. $join has signature <a<s>s?:s>; it accepts an array of strings and an optional joiner string which defaults to the empty string. It returns a string.
    - - if this argument is missing, use the context value ("focus").
        E.g. $length has signature <s-:n>; it can be called as $length(OrderID) (one argument) but equivalently as OrderID.$length().

Is it possible to define a signature that accepts 0 or more json types (varargs)? I want to support something like:

expression.registerFunction("myFunction", (...args) => ..., "?")