What's an operon?
An operon is a free operation that can types can adopt.
Think of them as functors, or single-function protocols.
npm i --save operon
This module exports operon
, which defines new operons,
and adopt
, an operon that operates on constructors,
mutating them to define an operation on their prototype.
Under the hood, operons use Symbols to safely extend arbitrary prototypes.
Example
const operon adopts = const count = Object adopts count 1Array adopts count _lengthString adopts count _length // Types can implement operons directly { return 100 } console // 100 // Or with adopts {}AnotherType adopts count 100 console // 100 console // 5console // equivalently, 5console // 1console // 3