Some invariants involve more than one field. Moving units from one bin to another should not decrement the source and then discover that the destination is invalid. Validate the whole request before the first mutation, or prepare a new state and publish it only after validation succeeds. This lesson uses local values and maps to practice that all-or-nothing boundary. It is not a database transaction simulator. A real database adds isolation, durability and concurrent conflict rules that these small functions do not provide. The tasks check both the returned success flag and the caller's state after a refusal. A function that reports an error but leaves half an update behind is still wrong. Include a same-record operation and a zero-quantity request when tracing your code.
Move units between both records.