← All procedures

client.reduce

Reduce an array: run fn for each item (acc and item are $refs)

MCPCLIbrowser
Package
@procedures/client · README
Path
["client","reduce"]
CLI
mark client reduce
MCP tool
client.reduce on the dev-tools server
As data
{"$proc":["client","reduce"],"input":{}}
Tags
core, collection, runs-refs

Try it in the Composer →

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY, allCoreProcedures } from "@procedures/client";

for (const procedure of allCoreProcedures) {
  if (!PROCEDURE_REGISTRY.has(procedure.path)) PROCEDURE_REGISTRY.register(procedure);
}

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["client","reduce"], { items: [], initial: "<initial>" });
console.log(JSON.stringify(result));

From the command line

$ mark client reduce

As data, in a program

{
  "$proc": ["client", "reduce"],
  "input": { "items": [], "initial": "<initial>" }
}

Input

FieldTypeRequired
itemsunknown[]yes
initialunknownyes
fnunknownno
accumulatedunknownno

Output

The schema does not list fields (any).

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "items": {
        "description": "The array, or a call that gives it"
      },
      "initial": {
        "description": "The first accumulator value"
      },
      "fn": {
        "description": "The call to run for each item. It reads { $ref: \"acc\" }, { $ref: \"item\" } and { $ref: \"index\" }; its result is the next accumulator."
      },
      "accumulated": {
        "description": "A result that was computed before (old form)"
      }
    },
    "additionalProperties": {}
  },
  "output": {
    "description": "The last accumulator: its shape depends on the program"
  }
}