functionalscript 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dev/index.d.ts +1 -0
- package/dev/index.js +3 -0
- package/dev/module.f.d.ts +2 -12
- package/dev/module.f.js +29 -55
- package/dev/test/module.d.ts +1 -0
- package/dev/test/module.f.d.ts +1 -6
- package/dev/test/module.f.js +3 -3
- package/dev/test/module.js +3 -0
- package/djs/parser/module.f.d.ts +2 -2
- package/djs/parser/module.f.js +1 -1
- package/djs/transpiler/module.f.d.ts +2 -2
- package/djs/transpiler/module.f.js +1 -1
- package/djs/transpiler/test.f.js +1 -1
- package/fsc/module.d.ts +2 -0
- package/fsc/module.js +4 -0
- package/io/module.d.ts +4 -0
- package/io/module.js +36 -0
- package/io/virtual.f.d.ts +2 -2
- package/io/virtual.f.js +1 -1
- package/js/tokenizer/module.f.js +1 -1
- package/json/parser/module.f.d.ts +2 -2
- package/json/parser/module.f.js +4 -7
- package/package.json +11 -13
- package/types/map/module.f.d.ts +2 -12
- package/types/map/module.f.js +16 -21
- package/types/map/test.f.d.ts +2 -2
- package/types/map/test.f.js +17 -109
- package/types/object/module.f.d.ts +2 -2
- package/types/object/module.f.js +1 -1
- package/types/ordered_map/module.f.d.ts +12 -0
- package/types/ordered_map/module.f.js +22 -0
- package/types/ordered_map/test.f.d.ts +5 -0
- package/types/ordered_map/test.f.js +113 -0
- package/types/result/module.d.ts +5 -0
- package/types/result/module.js +13 -0
- package/fsc.js +0 -4
package/dev/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dev/index.js
ADDED
package/dev/module.f.d.ts
CHANGED
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
import type { Io } from '../io/module.f.ts';
|
|
2
|
-
import type { Sign } from '../types/function/compare/module.f.ts';
|
|
3
2
|
export declare const todo: () => never;
|
|
4
3
|
export type Module = {
|
|
5
4
|
readonly default?: unknown;
|
|
6
5
|
};
|
|
7
|
-
export type UnknownMap = {
|
|
8
|
-
readonly [k in string]: unknown;
|
|
9
|
-
};
|
|
10
|
-
type Entry<T> = readonly [string, T];
|
|
11
|
-
export declare const cmp: ([a]: Entry<unknown>, [b]: Entry<unknown>) => Sign;
|
|
12
6
|
export type ModuleMap = {
|
|
13
7
|
readonly [k in string]: Module;
|
|
14
8
|
};
|
|
15
|
-
export declare const remove_tail: (v: readonly string[]) => (dif: number) => string[];
|
|
16
|
-
export type MutableModuleMap = {
|
|
17
|
-
[k in string]: Module;
|
|
18
|
-
};
|
|
19
9
|
export declare const env: (io: Io) => (v: string) => string | undefined;
|
|
20
|
-
export declare const
|
|
10
|
+
export declare const allFiles: ({ fs: { promises: { readdir } } }: Io) => Promise<readonly string[]>;
|
|
11
|
+
export declare const loadModuleMap: (io: Io) => Promise<ModuleMap>;
|
|
21
12
|
export declare const index: (io: Io) => Promise<number>;
|
|
22
|
-
export {};
|
package/dev/module.f.js
CHANGED
|
@@ -1,77 +1,51 @@
|
|
|
1
1
|
import { updateVersion } from "./version/module.f.js";
|
|
2
2
|
export const todo = () => { throw 'not implemented'; };
|
|
3
|
-
|
|
4
|
-
export const remove_tail = (v) => (dif) => v.slice(0, v.length - dif);
|
|
3
|
+
const cmp = ([a], [b]) => a < b ? -1 : a > b ? 1 : 0;
|
|
5
4
|
export const env = ({ process: { env } }) => a => {
|
|
6
5
|
const r = Object.getOwnPropertyDescriptor(env, a);
|
|
7
6
|
return r === undefined ? undefined :
|
|
8
7
|
typeof r.get === 'function' ? r.get() :
|
|
9
8
|
r.value;
|
|
10
9
|
};
|
|
11
|
-
export const
|
|
12
|
-
const load = async () => {
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
if (name.endsWith('.f.mjs') ||
|
|
24
|
-
name.endsWith('.f.js') ||
|
|
25
|
-
(name.endsWith('.f.ts') && !existsSync(file.substring(0, file.length - 3) + '.js'))) {
|
|
26
|
-
const source = await asyncImport(`../${file}`);
|
|
27
|
-
map.push([file, source.default]);
|
|
28
|
-
}
|
|
10
|
+
export const allFiles = ({ fs: { promises: { readdir } } }) => {
|
|
11
|
+
const load = async (p) => {
|
|
12
|
+
let result = [];
|
|
13
|
+
for (const i of await readdir(p, { withFileTypes: true })) {
|
|
14
|
+
const { name } = i;
|
|
15
|
+
if (!name.startsWith('.')) {
|
|
16
|
+
const file = `${p}/${name}`;
|
|
17
|
+
if (i.isDirectory()) {
|
|
18
|
+
result = [...result, ...await load(file)];
|
|
19
|
+
continue;
|
|
29
20
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
await f('.');
|
|
33
|
-
map.sort(cmp);
|
|
34
|
-
return Object.fromEntries(map);
|
|
35
|
-
};
|
|
36
|
-
const map = await load();
|
|
37
|
-
const build = () => {
|
|
38
|
-
const d = {};
|
|
39
|
-
const getModule = (base) => (k) => {
|
|
40
|
-
const relativePath = k.split('/');
|
|
41
|
-
const dif = relativePath.filter(v => v === '..').length;
|
|
42
|
-
const path = [remove_tail(base)(dif), relativePath.filter(v => !['..', '.'].includes(v))]
|
|
43
|
-
.flat();
|
|
44
|
-
const pathStr = path.join('/');
|
|
45
|
-
{
|
|
46
|
-
const module = d[pathStr];
|
|
47
|
-
if (module !== void 0) {
|
|
48
|
-
return [pathStr, module];
|
|
21
|
+
if (name.endsWith('.js') || name.endsWith('.ts')) {
|
|
22
|
+
result = [...result, file];
|
|
49
23
|
}
|
|
50
24
|
}
|
|
51
|
-
{
|
|
52
|
-
const module = { default: map[pathStr] };
|
|
53
|
-
d[pathStr] = module;
|
|
54
|
-
return [pathStr, module];
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
{
|
|
58
|
-
const get = getModule(['.']);
|
|
59
|
-
for (const k of Object.keys(map)) {
|
|
60
|
-
get(k);
|
|
61
|
-
}
|
|
62
25
|
}
|
|
63
|
-
return
|
|
26
|
+
return result;
|
|
64
27
|
};
|
|
65
|
-
return
|
|
28
|
+
return load('.');
|
|
29
|
+
};
|
|
30
|
+
export const loadModuleMap = async (io) => {
|
|
31
|
+
const { fs: { existsSync }, asyncImport } = io;
|
|
32
|
+
let map = [];
|
|
33
|
+
for (const f of await allFiles(io)) {
|
|
34
|
+
if (f.endsWith('.f.js') ||
|
|
35
|
+
(f.endsWith('.f.ts') && !existsSync(f.substring(0, f.length - 3) + '.js'))) {
|
|
36
|
+
const source = await asyncImport(`../${f}`);
|
|
37
|
+
map = [...map, [f, source]];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return Object.fromEntries(map.toSorted(cmp));
|
|
66
41
|
};
|
|
67
42
|
export const index = async (io) => {
|
|
68
43
|
updateVersion(io);
|
|
69
44
|
const jj = './deno.json';
|
|
70
|
-
const n = '/module.f.ts';
|
|
71
45
|
const jsr_json = JSON.parse(await io.fs.promises.readFile(jj, 'utf8'));
|
|
72
|
-
const list =
|
|
46
|
+
const list = (await allFiles(io)).filter(v => v.endsWith('/module.f.ts') || v.endsWith('/module.ts'));
|
|
73
47
|
//console.log(list)
|
|
74
|
-
const exportsA = list.
|
|
48
|
+
const exportsA = list.map(v => [v, `./${v.substring(2)}`]);
|
|
75
49
|
// console.log(exportsA)
|
|
76
50
|
const exports = Object.fromEntries(exportsA);
|
|
77
51
|
// console.log(exports)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dev/test/module.f.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type * as Result from '../../types/result/module.f.ts';
|
|
2
2
|
import type { Io, Performance } from '../../io/module.f.ts';
|
|
3
|
-
type
|
|
4
|
-
readonly default?: unknown;
|
|
5
|
-
};
|
|
6
|
-
type ModuleMap = {
|
|
7
|
-
readonly [k in string]: Module;
|
|
8
|
-
};
|
|
3
|
+
import { type ModuleMap } from '../module.f.ts';
|
|
9
4
|
type Log<T> = (v: string) => (state: T) => T;
|
|
10
5
|
type Measure<T> = <R>(f: () => R) => (state: T) => readonly [R, number, T];
|
|
11
6
|
type Input<T> = {
|
package/dev/test/module.f.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { entries, fold } from "../../types/list/module.f.js";
|
|
2
2
|
import { reset, fgGreen, fgRed, bold } from "../../text/sgr/module.f.js";
|
|
3
3
|
import { env, loadModuleMap } from "../module.f.js";
|
|
4
|
-
const isTest = (s) => s.endsWith('test.f.
|
|
4
|
+
const isTest = (s) => s.endsWith('test.f.js') || s.endsWith('test.f.ts');
|
|
5
5
|
const addPass = (delta) => (ts) => ({ ...ts, time: ts.time + delta, pass: ts.pass + 1 });
|
|
6
6
|
const addFail = (delta) => (ts) => ({ ...ts, time: ts.time + delta, fail: ts.fail + 1 });
|
|
7
7
|
const timeFormat = (a) => {
|
|
@@ -15,7 +15,7 @@ const timeFormat = (a) => {
|
|
|
15
15
|
};
|
|
16
16
|
export const test = (input) => {
|
|
17
17
|
let { moduleMap, log, error, measure, tryCatch, env, state } = input;
|
|
18
|
-
const isGitHub = env('GITHUB_ACTION') !==
|
|
18
|
+
const isGitHub = env('GITHUB_ACTION') !== undefined;
|
|
19
19
|
const f = ([k, v]) => {
|
|
20
20
|
const test = i => v => ([ts, state]) => {
|
|
21
21
|
const next = test(`${i}| `);
|
|
@@ -91,5 +91,5 @@ export const main = async (io) => test({
|
|
|
91
91
|
measure: measure(io.performance),
|
|
92
92
|
tryCatch: io.tryCatch,
|
|
93
93
|
env: env(io),
|
|
94
|
-
state:
|
|
94
|
+
state: undefined,
|
|
95
95
|
})[0];
|
package/djs/parser/module.f.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import * as result from '../../types/result/module.f.ts';
|
|
2
2
|
import { type List } from '../../types/list/module.f.ts';
|
|
3
3
|
import type { DjsToken } from '../tokenizer/module.f.ts';
|
|
4
|
-
import { type
|
|
4
|
+
import { type OrderedMap } from '../../types/ordered_map/module.f.ts';
|
|
5
5
|
import type { Fs } from '../../io/module.f.ts';
|
|
6
6
|
import type { AstModule } from '../ast/module.f.ts';
|
|
7
7
|
export type ParseContext = {
|
|
8
8
|
readonly fs: Fs;
|
|
9
|
-
readonly complete:
|
|
9
|
+
readonly complete: OrderedMap<result.Result<AstModule, string>>;
|
|
10
10
|
readonly stack: List<string>;
|
|
11
11
|
};
|
|
12
12
|
export declare const parseFromTokens: (tokenList: List<DjsToken>) => result.Result<AstModule, string>;
|
package/djs/parser/module.f.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as result from "../../types/result/module.f.js";
|
|
2
2
|
import { fold, first, drop, toArray, length, concat } from "../../types/list/module.f.js";
|
|
3
|
-
import { setReplace, at } from "../../types/
|
|
3
|
+
import { setReplace, at } from "../../types/ordered_map/module.f.js";
|
|
4
4
|
import { fromMap } from "../../types/object/module.f.js";
|
|
5
5
|
const parseInitialOp = token => state => {
|
|
6
6
|
switch (token.kind) {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type * as djs from '../module.f.ts';
|
|
2
2
|
import { type Result } from '../../types/result/module.f.ts';
|
|
3
3
|
import { type List } from '../../types/list/module.f.ts';
|
|
4
|
-
import { type
|
|
4
|
+
import { type OrderedMap } from '../../types/ordered_map/module.f.ts';
|
|
5
5
|
import type { Fs } from '../../io/module.f.ts';
|
|
6
6
|
export type ParseContext = {
|
|
7
7
|
readonly fs: Fs;
|
|
8
|
-
readonly complete:
|
|
8
|
+
readonly complete: OrderedMap<djsResult>;
|
|
9
9
|
readonly stack: List<string>;
|
|
10
10
|
readonly error: string | null;
|
|
11
11
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { error, ok } from "../../types/result/module.f.js";
|
|
2
2
|
import { fold, drop, map as listMap, toArray, includes } from "../../types/list/module.f.js";
|
|
3
3
|
import { tokenize } from "../tokenizer/module.f.js";
|
|
4
|
-
import { setReplace, at } from "../../types/
|
|
4
|
+
import { setReplace, at } from "../../types/ordered_map/module.f.js";
|
|
5
5
|
import { stringToList } from "../../text/utf16/module.f.js";
|
|
6
6
|
import { concat as pathConcat } from "../../path/module.f.js";
|
|
7
7
|
import { parseFromTokens } from "../parser/module.f.js";
|
package/djs/transpiler/test.f.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { sort } from "../../types/object/module.f.js";
|
|
2
|
-
import { setReplace } from "../../types/
|
|
2
|
+
import { setReplace } from "../../types/ordered_map/module.f.js";
|
|
3
3
|
import { transpile } from "./module.f.js";
|
|
4
4
|
import { stringify } from "../serializer/module.f.js";
|
|
5
5
|
import { createVirtualIo } from "../../io/virtual.f.js";
|
package/fsc/module.d.ts
ADDED
package/fsc/module.js
ADDED
package/io/module.d.ts
ADDED
package/io/module.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
9
|
+
import { run } from "./module.f.js";
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import process from "node:process";
|
|
12
|
+
export const io = {
|
|
13
|
+
console,
|
|
14
|
+
fs,
|
|
15
|
+
process,
|
|
16
|
+
asyncImport: (v) => import(__rewriteRelativeImportExtension(v)),
|
|
17
|
+
performance,
|
|
18
|
+
tryCatch: f => {
|
|
19
|
+
try {
|
|
20
|
+
return ['ok', f()];
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
return ['error', e];
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
asyncTryCatch: async (f) => {
|
|
27
|
+
try {
|
|
28
|
+
return ['ok', await f()];
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
return ['error', e];
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
const runDefault = run(io);
|
|
36
|
+
export default runDefault;
|
package/io/virtual.f.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Io } from './module.f.ts';
|
|
2
|
-
import { type
|
|
3
|
-
export declare const createVirtualIo: (files:
|
|
2
|
+
import { type OrderedMap } from '../types/ordered_map/module.f.ts';
|
|
3
|
+
export declare const createVirtualIo: (files: OrderedMap<string>) => Io;
|
package/io/virtual.f.js
CHANGED
package/js/tokenizer/module.f.js
CHANGED
|
@@ -2,7 +2,7 @@ import * as operator from "../../types/function/operator/module.f.js";
|
|
|
2
2
|
import * as range_map from "../../types/range_map/module.f.js";
|
|
3
3
|
const { merge, fromRange, get } = range_map;
|
|
4
4
|
import * as list from "../../types/list/module.f.js";
|
|
5
|
-
import * as map from "../../types/
|
|
5
|
+
import * as map from "../../types/ordered_map/module.f.js";
|
|
6
6
|
const { at } = map;
|
|
7
7
|
import * as _range from "../../types/range/module.f.js";
|
|
8
8
|
const { one } = _range;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as result from '../../types/result/module.f.ts';
|
|
2
|
-
import
|
|
2
|
+
import { type List } from '../../types/list/module.f.ts';
|
|
3
3
|
import type * as Tokenizer from '../tokenizer/module.f.ts';
|
|
4
4
|
import type * as Json from '../module.f.ts';
|
|
5
|
-
export declare const parse: (tokenList:
|
|
5
|
+
export declare const parse: (tokenList: List<Tokenizer.JsonToken>) => result.Result<Json.Unknown, string>;
|
package/json/parser/module.f.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import * as result from "../../types/result/module.f.js";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
const { setReplace } = map;
|
|
6
|
-
import * as o from "../../types/object/module.f.js";
|
|
7
|
-
const { fromMap } = o;
|
|
2
|
+
import { fold, first, drop, toArray, concat } from "../../types/list/module.f.js";
|
|
3
|
+
import { setReplace } from "../../types/ordered_map/module.f.js";
|
|
4
|
+
import { fromMap } from "../../types/object/module.f.js";
|
|
8
5
|
const addKeyToObject = obj => key => ({ kind: 'object', values: obj.values, key: key });
|
|
9
6
|
const addValueToObject = obj => value => ({ kind: 'object', values: setReplace(obj.key)(value)(obj.values), key: '' });
|
|
10
|
-
const addToArray = array => value => ({ kind: 'array', values:
|
|
7
|
+
const addToArray = array => value => ({ kind: 'array', values: concat(array.values)([value]) });
|
|
11
8
|
const pushKey = state => value => {
|
|
12
9
|
if (state.top?.kind === 'object') {
|
|
13
10
|
return { status: '{k', top: addKeyToObject(state.top)(value), stack: state.stack };
|
package/package.json
CHANGED
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functionalscript",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"**/*.f.d.ts",
|
|
9
|
-
"**/*.f.js"
|
|
6
|
+
"**/*.js",
|
|
7
|
+
"**/*.d.ts"
|
|
10
8
|
],
|
|
11
9
|
"description": "FunctionalScript is a functional subset of JavaScript",
|
|
12
10
|
"scripts": {
|
|
13
11
|
"tsc-emit": "tsc --NoEmit false",
|
|
14
|
-
"n": "node --
|
|
12
|
+
"n": "node --trace-uncaught",
|
|
15
13
|
"prepack": "npm run tsc-emit",
|
|
16
14
|
"git-clean": "git clean -xf",
|
|
17
|
-
"test20": "npm run tsc-emit && npm run n ./dev/test.js",
|
|
18
|
-
"test22": "tsc && npm run n -- --experimental-strip-types ./dev/test.ts",
|
|
19
|
-
"test": "tsc && npm run n ./dev/test.ts",
|
|
15
|
+
"test20": "npm run tsc-emit && npm run n ./dev/test/module.js",
|
|
16
|
+
"test22": "tsc && npm run n -- --experimental-strip-types ./dev/test/module.ts",
|
|
17
|
+
"test": "tsc && npm run n ./dev/test/module.ts",
|
|
20
18
|
"index": "npm run n ./dev/index.ts",
|
|
21
|
-
"fsc": "npm run n ./fsc.ts",
|
|
19
|
+
"fsc": "npm run n ./fsc/module.ts",
|
|
22
20
|
"update": "npm run index && npm install"
|
|
23
21
|
},
|
|
24
22
|
"engines": {
|
|
25
23
|
"node": ">=16"
|
|
26
24
|
},
|
|
27
25
|
"bin": {
|
|
28
|
-
"fsc": "fsc.js"
|
|
26
|
+
"fsc": "fsc/module.js"
|
|
29
27
|
},
|
|
30
28
|
"repository": {
|
|
31
29
|
"type": "git",
|
|
@@ -47,7 +45,7 @@
|
|
|
47
45
|
},
|
|
48
46
|
"homepage": "https://github.com/functionalscript/functionalscript#readme",
|
|
49
47
|
"devDependencies": {
|
|
50
|
-
"@types/node": "^22.
|
|
51
|
-
"typescript": "^5.8.
|
|
48
|
+
"@types/node": "^22.14",
|
|
49
|
+
"typescript": "^5.8.3"
|
|
52
50
|
}
|
|
53
51
|
}
|
package/types/map/module.f.d.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import type { Reduce } from '../function/operator/module.f.ts';
|
|
4
|
-
export type Entry<T> = readonly [string, T];
|
|
5
|
-
export type Map<T> = Tree<Entry<T>>;
|
|
6
|
-
export declare const at: (name: string) => <T>(map: Map<T>) => T | null;
|
|
7
|
-
export declare const setReduce: <T>(reduce: Reduce<T>) => (name: string) => (value: T) => (map: Map<T>) => Map<T>;
|
|
8
|
-
export declare const setReplace: (name: string) => <T>(value: T) => (map: Map<T>) => Map<T>;
|
|
9
|
-
export declare const entries: <T>(map: Map<T>) => List<Entry<T>>;
|
|
10
|
-
export declare const fromEntries: <T>(entries: List<Entry<T>>) => Map<T>;
|
|
11
|
-
export declare const remove: (name: string) => <T>(map: Map<T>) => Map<T>;
|
|
12
|
-
export declare const empty: null;
|
|
1
|
+
export declare const mapSet: <K, V>(map: ReadonlyMap<K, V>, k: K, v: V) => ReadonlyMap<K, V>;
|
|
2
|
+
export declare const mapDelete: <K, V>(map: ReadonlyMap<K, V>, k: K) => ReadonlyMap<K, V>;
|
package/types/map/module.f.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { cmp } from "../string/module.f.js";
|
|
6
|
-
import { fold } from "../list/module.f.js";
|
|
7
|
-
const keyCmp = a => ([b]) => cmp(a)(b);
|
|
8
|
-
export const at = (name) => (map) => {
|
|
9
|
-
if (map === null) {
|
|
10
|
-
return null;
|
|
1
|
+
const concat = (x, y) => ({
|
|
2
|
+
*[Symbol.iterator]() {
|
|
3
|
+
yield* x;
|
|
4
|
+
yield* y;
|
|
11
5
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export const
|
|
6
|
+
});
|
|
7
|
+
const filter = (i, p) => ({
|
|
8
|
+
*[Symbol.iterator]() {
|
|
9
|
+
for (const x of i) {
|
|
10
|
+
if (p(x)) {
|
|
11
|
+
yield x;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
export const mapSet = (map, k, v) => new Map(concat(map, [[k, v]]));
|
|
17
|
+
export const mapDelete = (map, k) => new Map(filter(map, ([xk]) => xk !== k));
|
package/types/map/test.f.d.ts
CHANGED
package/types/map/test.f.js
CHANGED
|
@@ -1,113 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { toArray } from "../list/module.f.js";
|
|
1
|
+
import { mapSet, mapDelete } from "./module.f.js";
|
|
3
2
|
export default {
|
|
4
|
-
|
|
5
|
-
()
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (at('c')(m) !== null) {
|
|
21
|
-
throw 'error';
|
|
22
|
-
}
|
|
23
|
-
m = setReplace('z')(3)(m);
|
|
24
|
-
if (at('a')(m) !== 1) {
|
|
25
|
-
throw 'error';
|
|
26
|
-
}
|
|
27
|
-
if (at('b')(m) !== 2) {
|
|
28
|
-
throw 'error';
|
|
29
|
-
}
|
|
30
|
-
if (at('z')(m) !== 3) {
|
|
31
|
-
throw 'error';
|
|
32
|
-
}
|
|
33
|
-
if (at('')(m) !== null) {
|
|
34
|
-
throw 'error';
|
|
35
|
-
}
|
|
36
|
-
m = setReplace('')(4)(m);
|
|
37
|
-
if (at('a')(m) !== 1) {
|
|
38
|
-
throw 'error';
|
|
39
|
-
}
|
|
40
|
-
if (at('b')(m) !== 2) {
|
|
41
|
-
throw 'error';
|
|
42
|
-
}
|
|
43
|
-
if (at('z')(m) !== 3) {
|
|
44
|
-
throw 'error';
|
|
45
|
-
}
|
|
46
|
-
if (at('')(m) !== 4) {
|
|
47
|
-
throw 'error';
|
|
48
|
-
}
|
|
49
|
-
if (at('Hello world!')(m) !== null) {
|
|
50
|
-
throw 'error';
|
|
51
|
-
}
|
|
52
|
-
m = setReplace('Hello world!')(42)(m);
|
|
53
|
-
if (at('a')(m) !== 1) {
|
|
54
|
-
throw 'error';
|
|
55
|
-
}
|
|
56
|
-
if (at('b')(m) !== 2) {
|
|
57
|
-
throw 'error';
|
|
58
|
-
}
|
|
59
|
-
if (at('z')(m) !== 3) {
|
|
60
|
-
throw 'error';
|
|
61
|
-
}
|
|
62
|
-
if (at('')(m) !== 4) {
|
|
63
|
-
throw 'error';
|
|
64
|
-
}
|
|
65
|
-
if (at('Hello world!')(m) !== 42) {
|
|
66
|
-
throw 'error';
|
|
67
|
-
}
|
|
68
|
-
if (at('x')(m) !== null) {
|
|
69
|
-
throw 'error';
|
|
70
|
-
}
|
|
71
|
-
// console.log(Array.from(m.entries()))
|
|
72
|
-
m = remove('Hello world!')(m);
|
|
73
|
-
if (at('Hello world!')(m) !== null) {
|
|
74
|
-
throw m;
|
|
75
|
-
}
|
|
76
|
-
m = setReduce((a) => (b) => a + b)('a')(43)(m);
|
|
77
|
-
if (at('a')(m) !== 44) {
|
|
78
|
-
throw 'error';
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
() => {
|
|
82
|
-
let m = setReplace('x')(12)(null);
|
|
83
|
-
m = setReplace('y')(44)(m);
|
|
84
|
-
if (at('x')(m) !== 12) {
|
|
85
|
-
throw 'error';
|
|
86
|
-
}
|
|
87
|
-
if (at('y')(m) !== 44) {
|
|
88
|
-
throw 'error';
|
|
89
|
-
}
|
|
90
|
-
if (at('a')(m) !== null) {
|
|
91
|
-
throw 'error';
|
|
92
|
-
}
|
|
93
|
-
const e = toArray(entries(m));
|
|
94
|
-
if (e.length !== 2) {
|
|
95
|
-
throw 'error';
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
stress: () => {
|
|
100
|
-
let m = empty;
|
|
101
|
-
for (let i = 0; i < 100_000; ++i) {
|
|
102
|
-
m = setReplace((i * i).toString())(i)(m);
|
|
103
|
-
/*
|
|
104
|
-
console.log()
|
|
105
|
-
console.log(`# ${i}`)
|
|
106
|
-
console.log()
|
|
107
|
-
for (const e of m.struct()) {
|
|
108
|
-
console.log(e)
|
|
109
|
-
}
|
|
110
|
-
*/
|
|
3
|
+
set: () => {
|
|
4
|
+
const map = mapSet(new Map(), 'a', 'b');
|
|
5
|
+
if (map.get('a') !== 'b') {
|
|
6
|
+
throw 'error';
|
|
7
|
+
}
|
|
8
|
+
if (map.size !== 1) {
|
|
9
|
+
throw 'error';
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
delete: () => {
|
|
13
|
+
const map = mapDelete(mapSet(new Map(), 'a', 'b'), 'a');
|
|
14
|
+
if (map.get('a') !== undefined) {
|
|
15
|
+
throw 'error';
|
|
16
|
+
}
|
|
17
|
+
if (map.size !== 0) {
|
|
18
|
+
throw 'error';
|
|
111
19
|
}
|
|
112
20
|
}
|
|
113
21
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type List } from '../list/module.f.ts';
|
|
2
|
-
import { type
|
|
2
|
+
import { type OrderedMap } from '../ordered_map/module.f.ts';
|
|
3
3
|
export type Map<T> = {
|
|
4
4
|
readonly [k in string]: T;
|
|
5
5
|
};
|
|
@@ -7,7 +7,7 @@ export type Entry<T> = readonly [string, T];
|
|
|
7
7
|
export declare const at: (name: string) => <T>(object: Map<T>) => T | null;
|
|
8
8
|
export declare const sort: <T>(e: List<Entry<T>>) => List<Entry<T>>;
|
|
9
9
|
export declare const fromEntries: <T>(e: List<Entry<T>>) => Map<T>;
|
|
10
|
-
export declare const fromMap: <T>(m:
|
|
10
|
+
export declare const fromMap: <T>(m: OrderedMap<T>) => Map<T>;
|
|
11
11
|
/**
|
|
12
12
|
* A set of objects with a single key.
|
|
13
13
|
*
|
package/types/object/module.f.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { iterable } from "../list/module.f.js";
|
|
2
|
-
import { entries as mapEntries, fromEntries as mapFromEntries } from "../
|
|
2
|
+
import { entries as mapEntries, fromEntries as mapFromEntries } from "../ordered_map/module.f.js";
|
|
3
3
|
const { getOwnPropertyDescriptor, fromEntries: objectFromEntries } = Object;
|
|
4
4
|
export const at = name => object => {
|
|
5
5
|
const r = getOwnPropertyDescriptor(object, name);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Tree } from '../btree/types/module.f.ts';
|
|
2
|
+
import { type List } from '../list/module.f.ts';
|
|
3
|
+
import type { Reduce } from '../function/operator/module.f.ts';
|
|
4
|
+
export type Entry<T> = readonly [string, T];
|
|
5
|
+
export type OrderedMap<T> = Tree<Entry<T>>;
|
|
6
|
+
export declare const at: (name: string) => <T>(map: OrderedMap<T>) => T | null;
|
|
7
|
+
export declare const setReduce: <T>(reduce: Reduce<T>) => (name: string) => (value: T) => (map: OrderedMap<T>) => OrderedMap<T>;
|
|
8
|
+
export declare const setReplace: (name: string) => <T>(value: T) => (map: OrderedMap<T>) => OrderedMap<T>;
|
|
9
|
+
export declare const entries: <T>(map: OrderedMap<T>) => List<Entry<T>>;
|
|
10
|
+
export declare const fromEntries: <T>(entries: List<Entry<T>>) => OrderedMap<T>;
|
|
11
|
+
export declare const remove: (name: string) => <T>(map: OrderedMap<T>) => OrderedMap<T>;
|
|
12
|
+
export declare const empty: null;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { value, find } from "../btree/find/module.f.js";
|
|
2
|
+
import { set } from "../btree/set/module.f.js";
|
|
3
|
+
import { remove as btreeRemove } from "../btree/remove/module.f.js";
|
|
4
|
+
import { values } from "../btree/module.f.js";
|
|
5
|
+
import { cmp } from "../string/module.f.js";
|
|
6
|
+
import { fold } from "../list/module.f.js";
|
|
7
|
+
const keyCmp = a => ([b]) => cmp(a)(b);
|
|
8
|
+
export const at = (name) => (map) => {
|
|
9
|
+
if (map === null) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const result = value(find(keyCmp(name))(map).first);
|
|
13
|
+
return result === null ? null : result[1];
|
|
14
|
+
};
|
|
15
|
+
const setReduceEntry = reduce => entry => set(keyCmp(entry[0]))(old => old === null ? entry : [old[0], reduce(old[1])(entry[1])]);
|
|
16
|
+
export const setReduce = reduce => name => value => setReduceEntry(reduce)([name, value]);
|
|
17
|
+
const replace = () => b => b;
|
|
18
|
+
export const setReplace = name => value => setReduceEntry(replace)([name, value]);
|
|
19
|
+
export const entries = values;
|
|
20
|
+
export const fromEntries = fold(setReduceEntry(replace))(null);
|
|
21
|
+
export const remove = name => btreeRemove(keyCmp(name));
|
|
22
|
+
export const empty = null;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { at, setReplace, setReduce, empty, entries, remove } from "./module.f.js";
|
|
2
|
+
import { toArray } from "../list/module.f.js";
|
|
3
|
+
export default {
|
|
4
|
+
main: [
|
|
5
|
+
() => {
|
|
6
|
+
let m = setReplace('a')(1)(null);
|
|
7
|
+
if (at('a')(m) !== 1) {
|
|
8
|
+
throw 'error';
|
|
9
|
+
}
|
|
10
|
+
if (at('b')(m) !== null) {
|
|
11
|
+
throw 'error';
|
|
12
|
+
}
|
|
13
|
+
m = setReplace('b')(2)(m);
|
|
14
|
+
if (at('a')(m) !== 1) {
|
|
15
|
+
throw 'error';
|
|
16
|
+
}
|
|
17
|
+
if (at('b')(m) !== 2) {
|
|
18
|
+
throw 'error';
|
|
19
|
+
}
|
|
20
|
+
if (at('c')(m) !== null) {
|
|
21
|
+
throw 'error';
|
|
22
|
+
}
|
|
23
|
+
m = setReplace('z')(3)(m);
|
|
24
|
+
if (at('a')(m) !== 1) {
|
|
25
|
+
throw 'error';
|
|
26
|
+
}
|
|
27
|
+
if (at('b')(m) !== 2) {
|
|
28
|
+
throw 'error';
|
|
29
|
+
}
|
|
30
|
+
if (at('z')(m) !== 3) {
|
|
31
|
+
throw 'error';
|
|
32
|
+
}
|
|
33
|
+
if (at('')(m) !== null) {
|
|
34
|
+
throw 'error';
|
|
35
|
+
}
|
|
36
|
+
m = setReplace('')(4)(m);
|
|
37
|
+
if (at('a')(m) !== 1) {
|
|
38
|
+
throw 'error';
|
|
39
|
+
}
|
|
40
|
+
if (at('b')(m) !== 2) {
|
|
41
|
+
throw 'error';
|
|
42
|
+
}
|
|
43
|
+
if (at('z')(m) !== 3) {
|
|
44
|
+
throw 'error';
|
|
45
|
+
}
|
|
46
|
+
if (at('')(m) !== 4) {
|
|
47
|
+
throw 'error';
|
|
48
|
+
}
|
|
49
|
+
if (at('Hello world!')(m) !== null) {
|
|
50
|
+
throw 'error';
|
|
51
|
+
}
|
|
52
|
+
m = setReplace('Hello world!')(42)(m);
|
|
53
|
+
if (at('a')(m) !== 1) {
|
|
54
|
+
throw 'error';
|
|
55
|
+
}
|
|
56
|
+
if (at('b')(m) !== 2) {
|
|
57
|
+
throw 'error';
|
|
58
|
+
}
|
|
59
|
+
if (at('z')(m) !== 3) {
|
|
60
|
+
throw 'error';
|
|
61
|
+
}
|
|
62
|
+
if (at('')(m) !== 4) {
|
|
63
|
+
throw 'error';
|
|
64
|
+
}
|
|
65
|
+
if (at('Hello world!')(m) !== 42) {
|
|
66
|
+
throw 'error';
|
|
67
|
+
}
|
|
68
|
+
if (at('x')(m) !== null) {
|
|
69
|
+
throw 'error';
|
|
70
|
+
}
|
|
71
|
+
// console.log(Array.from(m.entries()))
|
|
72
|
+
m = remove('Hello world!')(m);
|
|
73
|
+
if (at('Hello world!')(m) !== null) {
|
|
74
|
+
throw m;
|
|
75
|
+
}
|
|
76
|
+
m = setReduce((a) => (b) => a + b)('a')(43)(m);
|
|
77
|
+
if (at('a')(m) !== 44) {
|
|
78
|
+
throw 'error';
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
() => {
|
|
82
|
+
let m = setReplace('x')(12)(null);
|
|
83
|
+
m = setReplace('y')(44)(m);
|
|
84
|
+
if (at('x')(m) !== 12) {
|
|
85
|
+
throw 'error';
|
|
86
|
+
}
|
|
87
|
+
if (at('y')(m) !== 44) {
|
|
88
|
+
throw 'error';
|
|
89
|
+
}
|
|
90
|
+
if (at('a')(m) !== null) {
|
|
91
|
+
throw 'error';
|
|
92
|
+
}
|
|
93
|
+
const e = toArray(entries(m));
|
|
94
|
+
if (e.length !== 2) {
|
|
95
|
+
throw 'error';
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
stress: () => {
|
|
100
|
+
let m = empty;
|
|
101
|
+
for (let i = 0; i < 100_000; ++i) {
|
|
102
|
+
m = setReplace((i * i).toString())(i)(m);
|
|
103
|
+
/*
|
|
104
|
+
console.log()
|
|
105
|
+
console.log(`# ${i}`)
|
|
106
|
+
console.log()
|
|
107
|
+
for (const e of m.struct()) {
|
|
108
|
+
console.log(e)
|
|
109
|
+
}
|
|
110
|
+
*/
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
};
|
package/fsc.js
DELETED