How to use genfun - 1 common examples

To help you get started, we’ve selected a few genfun examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graalvm / graaljs / deps / npm / node_modules / protoduck / index.js View on Github external
}
    if (!argTypes) {
      argTypes = []
    }
    return new Constraint(this, thisType, argTypes)
  }
}
Duck.prototype.isDuck = true
Duck.prototype.isProtocol = true

const Protoduck = module.exports = define(['duck'], {
  createGenfun: ['duck', _metaCreateGenfun],
  addMethod: ['duck', _metaAddMethod]
}, { name: 'Protoduck' })

const noImplFound = module.exports.noImplFound = genfun.noApplicableMethod

module.exports.define = define
function define (types, spec, opts) {
  if (!isArray(types)) {
    // protocol(spec, opts?) syntax for method-based protocols
    opts = spec
    spec = types
    types = []
  }
  const duck = function (thisType, argTypes) {
    return duck.matches(thisType, argTypes)
  }
  Object.setPrototypeOf(duck, Duck.prototype)
  duck.isDerivable = true
  Object.defineProperty(duck, 'name', {
    value: (opts && opts.name) || 'Protocol'

genfun

Fast, prototype-friendly multimethods.

MIT
Latest version published 7 years ago

Package Health Score

68 / 100
Full package analysis

Popular genfun functions