If you need to ensure that math operations always return the result wrapped in a specific object, you can use Operand or subclass from it. For some practical examples, see its subclass Rest. If you need to keep nested operations, use Maybe.
Its creation is idempotent, that is Operand(Operand(x)) == Operand(x)
.
value |
Return a new instance of Operand, using an arbitrary object as value. |
Set or return the current value.
obj |
An Operand is equal to another one if their value are equal. |
Two instances with the same value return the same hash value.
This method is called to avoid nesting. You may override it in subclasses to perform actions on resulting values. Operand(Operand(1)) // Operand(1)
.