add comparison functions for SetIterator and DictIterator

This commit is contained in:
Joeri Exelmans 2025-05-09 16:51:29 +02:00
parent b0023afe8c
commit 1f2249e75a
5 changed files with 73 additions and 29 deletions

View file

@ -1,3 +1,5 @@
// The functions in this module prompt the user for actions to perform on types, instances, etc.
import { number, select } from "@inquirer/prompts";
import { getCompatibleInputTypes, getEnabledFunctions, getInstances, growEnv } from "../../lib/environment/env.js";
@ -11,9 +13,9 @@ import { genUUID } from "../../lib/util/random.js";
const defaultSelectOptions = {
pageSize: 13,
}
};
const proxyDynamic = async (env, dynamic) => {
export const proxyDynamic = async (env, dynamic) => {
const newEnv = growEnv(env)(dynamic);
const type = getType(dynamic)
if (eqType(type)(Type)) {
@ -26,9 +28,9 @@ const proxyDynamic = async (env, dynamic) => {
return proxyDynamic(newEnv, getInst(dynamic));
}
return listInstanceOptions(newEnv, dynamic);
}
};
const selectInstance = async (env, type, msg) => {
export const selectInstance = async (env, type, msg) => {
const instances = getInstances(env)(type);
const choices = foldSet(acc => instance => {
return [...acc, {
@ -48,7 +50,7 @@ const selectInstance = async (env, type, msg) => {
return createInstance(type);
}
return choice;
}
};
export const listInstances = async (env, type) => {
const choice = await selectInstance(env, type, "instances of");
@ -57,9 +59,9 @@ export const listInstances = async (env, type) => {
}
await proxyDynamic(env, newDynamic(choice)(type));
return await listInstances(env, type);
}
};
const listTypeOptions = async (env, type) => {
export const listTypeOptions = async (env, type) => {
const choice = await select({
message: `type ${pretty(type)}:`,
choices: [
@ -87,9 +89,9 @@ const listTypeOptions = async (env, type) => {
await listInstanceOptions(newDynamic(type)(Type));
}
return await listTypeOptions(env, type);
}
};
const listInstanceOptions = async (env, dynamic) => {
export const listInstanceOptions = async (env, dynamic) => {
const choice = await select({
message: `instance ${pretty(dynamic)}:`,
choices: [
@ -109,9 +111,9 @@ const listInstanceOptions = async (env, dynamic) => {
await listTypeOptions(env, getType(dynamic));
}
return await listInstanceOptions(env, dynamic);
}
};
const listFunctionOptions = async (env, dynamic) => {
export const listFunctionOptions = async (env, dynamic) => {
const choice = await select({
message: `function ${pretty(dynamic)}:`,
choices: [
@ -126,9 +128,9 @@ const listFunctionOptions = async (env, dynamic) => {
if (choice === "call") {
await call(env, dynamic);
}
}
};
const createInstance = async (type) => {
export const createInstance = async (type) => {
if (eqType(type)(Int)) {
const n = await number({
message: `enter an integer (leave empty to go back):`,
@ -185,9 +187,9 @@ export const transform = async (env, dynamic) => {
const outValue = getInst(fun)(getInst(dynamic));
await proxyDynamic(env, newDynamic(outValue)(outType));
return transform(env, dynamic);
}
};
const call = async (env, funDynamic) => {
export const call = async (env, funDynamic) => {
const funType = getType(funDynamic);
const inTypes = getCompatibleInputTypes(env)(funType);
const choice = inTypes.length === 1
@ -215,4 +217,4 @@ const call = async (env, funDynamic) => {
const outValue = getInst(funDynamic)(inValue);
await proxyDynamic(envWithInput, newDynamic(outValue)(choice.outType));
return call(env, funDynamic);
}
};