@jsoldi/hkt
Version:
Higher kinded types for typescript and a few utility monads.
22 lines • 649 B
JavaScript
import { id } from "../core/utils.js";
const is_functor = Symbol("is_functor");
function _functor(base) {
if (is_functor in base)
return base;
const fmap = (f) => (fa) => base.map(fa, f);
const nestFunctor = (g) => {
return _functor({
map: (fa, f) => base.map(fa, ga => g.map(ga, f))
});
};
return {
...{ [is_functor]: true },
fmap,
nestFunctor,
...base
};
}
_functor.const = () => _functor({ map: id });
/** The functor factory, providing a set of functions for working with functors. */
export const functor = _functor;
//# sourceMappingURL=functor.js.map