derive

Allows a function to provide functionality to variants in an union.

This feature is experimental!

This API is still experimental, so it may change or be removed in future versions. You should not rely on it for production applications.

Signature

derive(...derivations)
Union . (...(Variant, Union) => Any) => Union

Documentation

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
}

Properties

Source Code

derive(...derivations) {
    derivations.forEach(derivation => {
      this.variants.forEach(variant => derivation(variant, this));
    });
    return this;
  }
Stability
experimental
Licence
MIT
Module
folktale/adt/union/union
On This Page
Authors
Copyright
(c) 2013-2017 Quildreen Motta, and CONTRIBUTORS
Authors
  • Quildreen Motta
Maintainers
  • Quildreen Motta <queen@robotlolita.me> (http://robotlolita.me/)