UNPKG

@thi.ng/defmulti

Version:

Dynamic, extensible multiple dispatch via user supplied dispatch function.

18 lines (17 loc) 447 B
import { illegalArgs } from "@thi.ng/errors/illegal-arguments"; const implementations = (id, rels, ...impls) => { impls.length & 1 && illegalArgs("expected an even number of implementation items"); if (rels) { for (let parent in rels) { for (let fn of rels[parent]) { fn.isa(id, parent); } } } for (let i = 0; i < impls.length; i += 2) { impls[i].add(id, impls[i + 1]); } }; export { implementations };