create 'Ordering' type
This commit is contained in:
parent
77dfc8b182
commit
b0023afe8c
15 changed files with 158 additions and 117 deletions
|
|
@ -1,13 +1,9 @@
|
|||
import { number, select } from "@inquirer/prompts";
|
||||
|
||||
import { makeCompareFn } from "../../lib/compare/dynamic.js";
|
||||
import { getFunctions, getInstances, getTypes, growEnv } from "../../lib/environment/env.js";
|
||||
import { assignFn } from "../../lib/generics/generics.js";
|
||||
import { getCompatibleInputTypes, getEnabledFunctions, getInstances, growEnv } from "../../lib/environment/env.js";
|
||||
import { getInst, getType, newDynamic } from "../../lib/primitives/dynamic.js";
|
||||
import { Bool, Double, Int, SymbolDynamic, Type, UUID } from "../../lib/primitives/primitive_types.js";
|
||||
import { eqType, getSymbol } from "../../lib/primitives/type.js";
|
||||
import { ModuleStd } from "../../lib/stdlib.js";
|
||||
import { fold as foldList } from "../../lib/structures/list.js";
|
||||
import { fold as foldSet } from "../../lib/structures/set.js";
|
||||
import { symbolFunction } from "../../lib/structures/type_constructors.js";
|
||||
import { pretty, prettyT } from "../../lib/util/pretty.js";
|
||||
|
|
@ -168,20 +164,10 @@ const createInstance = async (type) => {
|
|||
console.log("no prompt handler for creating new", prettyT(type));
|
||||
};
|
||||
|
||||
const transform = async (env, dynamic) => {
|
||||
const allFunctions = getFunctions(env);
|
||||
const enabled = foldList(enabled => fun => {
|
||||
try {
|
||||
const outType = assignFn(getType(fun), getType(dynamic));
|
||||
return [...enabled, {fun, outType}];
|
||||
} catch (e) {
|
||||
// console.log('warning:', e);
|
||||
return enabled;
|
||||
}
|
||||
})([])(allFunctions);
|
||||
|
||||
export const transform = async (env, dynamic) => {
|
||||
const enabled = getEnabledFunctions(env)(dynamic);
|
||||
const choice = await select({
|
||||
message: `select:`,
|
||||
message: `select transformation:`,
|
||||
choices: [
|
||||
"(go back)",
|
||||
...enabled.map(({fun, outType}) => ({
|
||||
|
|
@ -203,18 +189,7 @@ const transform = async (env, dynamic) => {
|
|||
|
||||
const call = async (env, funDynamic) => {
|
||||
const funType = getType(funDynamic);
|
||||
const allTypes = getTypes(env);
|
||||
|
||||
// compatible input types
|
||||
const inTypes = foldSet(types => inType => {
|
||||
try {
|
||||
const outType = assignFn(funType, inType); // may throw
|
||||
return [...types, {inType, outType}];
|
||||
} catch (e) {
|
||||
return types;
|
||||
}
|
||||
})([])(allTypes);
|
||||
|
||||
const inTypes = getCompatibleInputTypes(env)(funType);
|
||||
const choice = inTypes.length === 1
|
||||
? inTypes[0]
|
||||
: await select({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue