@markandrus/effect-derive
Version:
Derive Covariant (Functor), Foldable, and Traversable instances, as well as base functors, for algebraic data types (ADTs)
28 lines (27 loc) • 702 B
JavaScript
export const unwrap = (wa) => {
return wa[1];
};
export const extract = (wa) => {
return wa[0];
};
export const duplicate = (F) => {
return function duplicate(self) {
return [self, F.map(unwrap(self), duplicate)];
};
};
export const extend = (F) => {
return function extend(self, f) {
return [f(self), F.map(unwrap(self), _ => extend(_, f))];
};
};
export const mapComposition = (F) => {
return function map(self, f) {
return [f(self[0]), F.map(self[1], _ => map(_, f))];
};
};
export const distHisto = (F) => {
F;
return function distHisto(self) {
return [F.map(self, extract), F.map(self, _ => distHisto(unwrap(_)))];
};
};