A Box is a way to combine two values into a new one. It is a specialization of the functional type
(V,V) => V
, where the first parameter is the old value of an unknown and the second parameter
is the new contribution. Both widenings and narrowings are examples of boxes. Boxes are mutable, i.e.,
the apply method may give different results for the same input when called multiple times.
Another function of boxes is to be blueprints for building other equivalent boxes. Each box has a copy
method which should produce a functionally equivalent copy of this
. The copy method should try to
minimize object duplication.
- Type parameters:
- V
the type of the values to combine.
- Companion:
- object
Value members
Abstract methods
Returns a copy of this box. An immutable box may just returns itself, but a mutable one should produce a distinct a copy of itself.
Returns a copy of this box. An immutable box may just returns itself, but a mutable one should produce a distinct a copy of itself.
It returns true if the box is guaranteed to be idempotent, i.e., if x box y = (x box y) box y
.
This may be used for optimization purposes.
It returns true if the box is guaranteed to be idempotent, i.e., if x box y = (x box y) box y
.
This may be used for optimization purposes.
It returns true if this box is immutable, i.e., if the apply
method does not change its behaviour
over time.
It returns true if this box is immutable, i.e., if the apply
method does not change its behaviour
over time.
It returns true if this is guaranteed to be the right box (i.e., the one which always returns the second component). This may be used for optimization purposes.
It returns true if this is guaranteed to be the right box (i.e., the one which always returns the second component). This may be used for optimization purposes.