dope2/lib/primitives/dynamic.js
2025-05-08 23:35:34 +02:00

26 lines
701 B
JavaScript

import { inspect } from "node:util";
import { assignFn } from "../generics/generics.js";
function inspectDynamic(_depth, options, inspect) {
return `${inspect(this.i, options)} :: ${inspect(this.t, options)}`;
}
export const newDynamic = i => t => ({
i, t,
[inspect.custom]: inspectDynamic,
});
export const getInst = lnk => lnk.i;
export const getType = lnk => lnk.t;
export const apply = input => fun => {
const inputType = getType(input)
const funType = getType(fun);
const outputType = assignFn(funType, inputType);
const inputValue = getInst(input);
const funValue = getInst(fun);
const outputValue = funValue(inputValue);
return newDynamic(outputValue, outputType);
};