← All procedures

optional.flatMap

This function applies `f`, which gives an optional, to a present value. An absent value stays absent.

CLI
Package
@procedures/optional · README
Path
["optional","flatMap"]
CLI
mark optional flatMap --o <object | object> --f <object>
As data
{"$proc":["optional","flatMap"],"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","flatMap"], { o: "<o>", f: {} });
console.log(JSON.stringify(result));

From the command line

$ mark optional flatMap --o <object | object> --f <object>

As data, in a program

{ "$proc": ["optional", "flatMap"], "input": { "o": "<o>", "f": {} } }

Input

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

Output

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

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "o": {
        "anyOf": [
          {
            "type": "object",
            "properties": {
              "tag": {
                "type": "string",
                "const": "none"
              }
            },
            "required": [
              "tag"
            ],
            "additionalProperties": {}
          },
          {
            "type": "object",
            "properties": {
              "tag": {
                "type": "string",
                "const": "some"
              },
              "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/Optional_U"
          }
        },
        "description": "One call of a pure procedure, as data, for the function (v: T) => Optional<U>. It reads each parameter as {\"$ref\": \"<name>\"}: v."
      }
    },
    "required": [
      "o",
      "f"
    ],
    "additionalProperties": false
  },
  "output": {
    "anyOf": [
      {
        "type": "object",
        "properties": {
          "tag": {
            "type": "string",
            "const": "none"
          }
        },
        "required": [
          "tag"
        ],
        "additionalProperties": {}
      },
      {
        "type": "object",
        "properties": {
          "tag": {
            "type": "string",
            "const": "some"
          },
          "value": {}
        },
        "required": [
          "tag",
          "value"
        ],
        "additionalProperties": {}
      }
    ]
  }
}