Allows a function to provide functionality to variants in an union.
This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.
Allows a function to provide functionality to variants in an union.
The derive
method exists to support meta-programming on union objects,
such that additional functionality (implementation of interfaces or
protocols, for example) may be provided by libraries instead of having
to be hand-coded by the user.
The operation accepts many derivation
functions, which will be invoked
for each variant in the union, where a Variant is just an object with the
following attributes:
interface Variant(Any...) -> 'a <: self.prototype {
tag : String,
type : Any,
constructor : Constructor,
prototype : Object
}
derive(...derivations) {
derivations.forEach(derivation => {
this.variants.forEach(variant => derivation(variant, this));
});
return this;
}