← All procedures

optional.fromSentinel

This function changes a value of the sentinel form into an optional. In the sentinel form, the value `sentinel` means "absent", for example a symbol `NotFound`.

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

From the command line

$ mark optional fromSentinel --value <any> --sentinel <any>

As data, in a program

{
  "$proc": ["optional", "fromSentinel"],
  "input": { "value": "<value>", "sentinel": "<sentinel>" }
}

Input

FieldTypeRequiredDefaultDescription
valueanyyes
sentinelanyyes

Output

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

JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "value": {},
      "sentinel": {}
    },
    "required": [
      "value",
      "sentinel"
    ],
    "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": {}
      }
    ]
  }
}