← All procedures

optional.flatMapResult

This function applies `f`, which gives a result, to a value. An error stays the same.

CLI
Package
@procedures/optional · README
Path
["optional","flatMapResult"]
CLI
mark optional flatMapResult --r <object | object> --f <object>
As data
{"$proc":["optional","flatMapResult"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/optional/register"; // registers its procedures

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

From the command line

$ mark optional flatMapResult --r <object | object> --f <object>

As data, in a program

{
  "$proc": ["optional", "flatMapResult"],
  "input": { "r": "<r>", "f": {} }
}

Input

FieldTypeRequiredDefaultDescription
robject | objectyes
fobjectyesOne call of a pure procedure, as data, for the function (v: T) => Result<U, F>. It reads each parameter as {"$ref": "<name>"}: v.

Output

The schema does not list fields (object | object).

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "r": {
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "tag": {
                "type": "string",
                "const": "err"
              },
              "error": {}
            },
            "required": [
              "tag",
              "error"
            ],
            "additionalProperties": {}
          },
          {
            "type": "object",
            "properties": {
              "tag": {
                "type": "string",
                "const": "ok"
              },
              "value": {}
            },
            "required": [
              "tag",
              "value"
            ],
            "additionalProperties": {}
          }
        ]
      },
      "f": {
        "type": "object",
        "properties": {
          "$proc": {
            "minItems": 1,
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "input": {},
          "$when": {
            "type": "string",
            "const": "$never"
          }
        },
        "required": [
          "$proc"
        ],
        "additionalProperties": {},
        "x-procedures-program": {
          "params": [
            "v"
          ],
          "inputs": [
            {}
          ],
          "output": {
            "$ref": "#/$defs/Result_U_F"
          }
        },
        "description": "One call of a pure procedure, as data, for the function (v: T) => Result<U, F>. It reads each parameter as {\"$ref\": \"<name>\"}: v."
      }
    },
    "required": [
      "r",
      "f"
    ],
    "additionalProperties": false
  },
  "output": {
    "anyOf": [
      {
        "type": "object",
        "properties": {
          "tag": {
            "type": "string",
            "const": "err"
          },
          "error": {}
        },
        "required": [
          "tag",
          "error"
        ],
        "additionalProperties": {}
      },
      {
        "type": "object",
        "properties": {
          "tag": {
            "type": "string",
            "const": "ok"
          },
          "value": {}
        },
        "required": [
          "tag",
          "value"
        ],
        "additionalProperties": {}
      }
    ]
  }
}