Operand:
Filter:
Classes | Core

Operand : AbstractFunction : Object

Idempotent wrapper around math operations
Source: Operand.sc
Subclasses: Rest

Description

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).

Class Methods

Operand.new(value)

Arguments:

value

Return a new instance of Operand, using an arbitrary object as value.

Inherited class methods

Instance Methods

.value

.value = value

Set or return the current value.

==(obj)

Arguments:

obj

An Operand is equal to another one if their value are equal.

.hash(obj)

Two instances with the same value return the same hash value.

.dereferenceOperand

This method is called to avoid nesting. You may override it in subclasses to perform actions on resulting values. Operand(Operand(1)) // Operand(1).

Inherited instance methods

Examples