Skip to main content

$block

The $block operator executes a block of expressions and returns the value of the last expression.

Input

  • An array of expressions to execute in sequence

Output

  • The value of the last expression in the block, or null if the block is empty

Examples

Basic Block

{
  "$block": [
    {
      "$let": [
        "x",
        5
      ]
    },
    {
      "$let": [
        "y",
        10
      ]
    },
    {
      "$add": [
        {
          "$var": ["x"]
        },
        {
          "$var": ["y"]
        }
      ]
    }
  ]
}
Result: 15

Block with Early Return

{
  "$block": [
    {
      "$let": [
        "value",
        {
          "$input": "input_value"
        }
      ]
    },
    {
      "$ifelse": [
        {
          "$lt": [
            {
              "$var": ["value"]
            },
            0
          ]
        },
        {
          "$return": [
            "negative"
          ]
        },
        {
          "$return": [
            "non-negative"
          ]
        }
      ]
    }
  ]
}
Result: "negative" if the input_value is negative, otherwise "non-negative"