3 ms·
Hm, I sort of ignored these when diving into ES6 at first, but they're perfect for making extensible sum types function match(t, matchers) { const va
by tel 11y ago
Hm, I sort of ignored these when diving into ES6 at first, but they're perfect for making extensible sum types
function match(t, matchers) {
const variant = t[Symbol.for('variant')];
return matchers[variant](t);
}
Previously one had to make the sum look something like
{ _variant: String
, _params: Obj
}
to ensure that you could work generically with them and not have the _params object accidentally clobber your variant. Underscore privates are nice, but... obviously a hack.