Multiset One Kit Consumption
Apply one all-or-nothing typed kit consumption; insufficient inventory remains unchanged rather than partially consumed.
Description
Apply one all-or-nothing typed kit consumption; insufficient inventory remains unchanged rather than partially consumed.
Consuming one complete kit requires every requested multiplicity to be available. Failure should leave the inventory unchanged.
When to use this tool
Apply one all-or-nothing typed kit consumption; insufficient inventory remains unchanged rather than partially consumed.
- Prepare the supplied inventoryJson, kitJson fields for this operation.
- Compare the complete example with the representation used by your own input before carrying the result into another step.
How to use the tool and how it works
- Enter inventoryJson, kitJson. Use the exact text syntax, units and index conventions explained below.
- Run the tool. If input validation fails, correct the supplied fields before interpreting any result.
- Read result.canConsume, result.remaining. Interpret false, null and empty lists using the distinctions below; they can be valid outputs.
Normalize inventoryJson and a nonempty positive kitJson. If every required count is available, subtract those counts and remove zero rows; otherwise return canConsume false and the normalized inventory unchanged.1
| Input field | Meaning and representation | Accepted input |
|---|---|---|
| inventoryJson | JSON text, entered as one text field. The decoded structure is illustrated below; it is not a separate file. | Text |
| kitJson | JSON text, entered as one text field. The decoded structure is illustrated below; it is not a separate file. | Text |
For the JSON text fields, the following decoded structures show the example records before they are serialized into input strings. Keep field names, list nesting and value types as shown.
[
{
"field": "inventoryJson",
"decoded": [
{
"value": "a",
"count": 3
},
{
"value": "b",
"count": 1
}
]
},
{
"field": "kitJson",
"decoded": [
{
"value": "a",
"count": 2
}
]
}
] | Output field | Interpretation |
|---|---|
| result | Object containing the named outputs below. |
| result.canConsume | Whether every required kit count is available before any subtraction. |
| result.remaining | The remaining list in the ordering and representation described above. |
{
"input": {
"inventoryJson": "[{\"value\":\"a\",\"count\":3},{\"value\":\"b\",\"count\":1}]",
"kitJson": "[{\"value\":\"a\",\"count\":2}]"
},
"output": {
"result": {
"canConsume": true,
"remaining": [
{
"value": "a",
"count": 1
},
{
"value": "b",
"count": 1
}
]
}
}
} Limitations and assumptions
- This is snapshot arithmetic, without atomic inventory storage or actual reservation. An empty effective kit is rejected rather than considered free consumption.
- All declared input fields are required and unexpected top-level fields are rejected. Numbers must be finite; lists are limited to 128 entries and ordinary text fields to 8,192 UTF-16 code units, with tighter limits where stated.
- JSON text inputs must parse within bounded nesting and size limits. Numeric outputs outside the safe finite range are rejected; large exact integer results use decimal strings. Indexes and half-open spans are zero-based unless a rank is explicitly described as one-based.
Alternative or Complementary methods
Keep occurrence sequences separate from count tables. Choose maximum union, additive concatenation or allocation deliberately, and apply any real inventory changes through a system that controls concurrent updates.
References
Similar or alternative tools
- Multiset Complete Kit Count
Count complete typed kits consumable from an explicit inventory using the limiting required multiplicity; empty kit requirements are rejected.
- Multiset Capped Count Table
Cap each normalized typed multiplicity at an explicit nonnegative integer and omit resulting zeros; no proportional redistribution.