Skip to content

Commit e81192d

Browse files
author
jared
committed
Refactored LambdaBuffers --> Prelude and associated prefixes
1 parent 4af7835 commit e81192d

18 files changed

+488
-492
lines changed

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
pname = packageJson.name;
3131
version = packageJson.version;
3232
src = ./.;
33-
npmDepsHash = "sha256-wSSYPXAfsoqghsYu5quUZCyimVHtWu+Cp7yee7qAi7E=";
33+
npmDepsHash = "sha256-0lKTLQwKeD0Smanjhnr7AMPCM8Am/l7zOyMwegMZVuA=";
3434
};
3535

3636
# Tarball created from `npm pack`

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"description": "A Prelude for TypeScript",
55
"lockfileVersion": 2,
66
"exports": {
7-
".": "./dist/LambdaBuffers/Prelude.js",
8-
"./Map.js": "./dist/LambdaBuffers/Runtime/Map.js",
9-
"./Set.js": "./dist/LambdaBuffers/Runtime/Set.js",
7+
".": "./dist/Prelude/Prelude.js",
8+
"./Map.js": "./dist/Prelude/Runtime/Map.js",
9+
"./Set.js": "./dist/Prelude/Runtime/Set.js",
1010
"./package.json": "./package.json"
1111
},
1212
"type": "module",
1313
"scripts": {
14-
"build": "npx tsc -b src/LambdaBuffers",
14+
"build": "npx tsc -b src/Prelude",
1515
"test": "npx tsc -b src/Tests && node --test"
1616
},
1717
"repository": {
@@ -24,6 +24,6 @@
2424
"typescript": "^5.2.2",
2525
"@types/node": "^20.8.10"
2626
},
27-
"files": ["./dist/LambdaBuffers/**/*"],
27+
"files": ["./dist/Prelude/**/*"],
2828
"dependencies": {}
2929
}

src/LambdaBuffers/Prelude.ts renamed to src/Prelude/Prelude.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,3 @@ export * from "./Runtime/Either.js";
44
export * from "./Runtime/Json.js";
55
export * from "./Runtime/Ord.js";
66
export * from "./Runtime/Eq.js";
7-
8-
export function and(l: boolean, r: boolean) {
9-
return l && r;
10-
}
File renamed without changes.

src/LambdaBuffers/Runtime/Either.ts renamed to src/Prelude/Runtime/Either.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as LbJson from "./Json.js";
1+
import * as PJson from "./Json.js";
22
import type { Eq } from "./Eq.js";
33
import type { Ord } from "./Ord.js";
44
import type { Json } from "./Json.js";
@@ -72,17 +72,17 @@ export function jsonEither<L, R>(
7272
return {
7373
toJson: (either) => {
7474
if (either.name === "Left") {
75-
return LbJson.jsonConstructor("Left", [
75+
return PJson.jsonConstructor("Left", [
7676
dict1.toJson(either.fields),
7777
]);
7878
} else {
79-
return LbJson.jsonConstructor("Right", [
79+
return PJson.jsonConstructor("Right", [
8080
dict2.toJson(either.fields),
8181
]);
8282
}
8383
},
8484
fromJson: (value) => {
85-
return LbJson.caseJsonConstructor<Either<L, R>>("Prelude.Either", {
85+
return PJson.caseJsonConstructor<Either<L, R>>("Prelude.Either", {
8686
"Left": (ctorFields) => {
8787
if (ctorFields.length === 1) {
8888
return {
@@ -92,7 +92,7 @@ export function jsonEither<L, R>(
9292
} else {
9393
throw new JsonError(
9494
"Expected JSON Array with 1 fields but got" +
95-
LbJson.stringify(value),
95+
PJson.stringify(value),
9696
);
9797
}
9898
},
@@ -105,7 +105,7 @@ export function jsonEither<L, R>(
105105
} else {
106106
throw new JsonError(
107107
"Expected JSON Array with 1 fields but got" +
108-
LbJson.stringify(value),
108+
PJson.stringify(value),
109109
);
110110
}
111111
},
File renamed without changes.

src/LambdaBuffers/Runtime/Json.ts renamed to src/Prelude/Runtime/Json.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Ord } from "./Ord.js";
2-
import * as LbMap from "./Map.js";
2+
import * as PMap from "./Map.js";
33
/**
44
* `Json<A>` is a type class to provide `toJson` and `fromJson` instances for
55
* type `A`.
@@ -295,9 +295,9 @@ export function caseJsonMap<K, V>(
295295
dictOrd: Ord<K>,
296296
parseElem: (arg: [Value, Value]) => [K, V],
297297
value: Readonly<Value>,
298-
): LbMap.Map<K, V> {
298+
): PMap.Map<K, V> {
299299
// TODO(jaredponn): actually use `title` in the error messages.
300-
const map: LbMap.Map<K, V> = new LbMap.Map();
300+
const map: PMap.Map<K, V> = new PMap.Map();
301301

302302
if (!isJsonArray(value)) {
303303
throw new JsonError(`Expected JSON array`);
@@ -310,10 +310,10 @@ export function caseJsonMap<K, V>(
310310

311311
const [k, v] = parseElem(kv as [Value, Value]);
312312

313-
LbMap.insert(dictOrd, k, v, map);
313+
PMap.insert(dictOrd, k, v, map);
314314
}
315315

316-
if (LbMap.toList(map).length !== value.length) {
316+
if (PMap.toList(map).length !== value.length) {
317317
throw new JsonError(`Map should have unique keys`);
318318
}
319319

src/LambdaBuffers/Runtime/Map.ts renamed to src/Prelude/Runtime/Map.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Ord } from "./Ord.js";
2-
import * as LbAvlTree from "./AvlTree.js";
2+
import * as PAvlTree from "./AvlTree.js";
33
import type { Node } from "./AvlTree.js";
44
import type { Maybe } from "./Maybe.js";
55

@@ -8,19 +8,19 @@ import type { Maybe } from "./Maybe.js";
88
*
99
* @example
1010
* ```ts
11-
* import * as LbPrelude from "lbr-prelude"
11+
* import * as Prelude from "lbr-prelude"
1212
*
1313
* let map : Map<string, string> = new Map();
14-
* insert(LbPrelude.ordString, "a", "b", map)
15-
* lookup(LbPrelude.ordString, "a", map) // returns `"b"`
14+
* insert(Prelude.ordString, "a", "b", map)
15+
* lookup(Prelude.ordString, "a", map) // returns `"b"`
1616
* map.length // is 1
1717
*
18-
* insert(LbPrelude.ordString. "a", "c", map)
19-
* lookup(LbPrelude.ordString, "a", map) // returns `"c"`
18+
* insert(Prelude.ordString. "a", "c", map)
19+
* lookup(Prelude.ordString, "a", map) // returns `"c"`
2020
* map.length // is 1
2121
*
22-
* remove(LbPrelude.ordString, "a", map)
23-
* lookup(LbPrelude.ordString, "a", map) // returns `undefined`
22+
* remove(Prelude.ordString, "a", map)
23+
* lookup(Prelude.ordString, "a", map) // returns `undefined`
2424
* map.length // is 0
2525
* ```
2626
*/
@@ -66,7 +66,7 @@ export function insert<K, V>(
6666
value: V,
6767
map: Map<K, V>,
6868
): void {
69-
map.tree = LbAvlTree.alter(
69+
map.tree = PAvlTree.alter(
7070
ordOnFst(ordDict),
7171
(arg) => {
7272
if (arg === undefined) {
@@ -88,7 +88,7 @@ export function insert<K, V>(
8888
* Complexity: `O(log n)`
8989
*/
9090
export function remove<K, V>(ordDict: Ord<K>, key: K, map: Map<K, V>): void {
91-
map.tree = LbAvlTree.alter(
91+
map.tree = PAvlTree.alter(
9292
ordOnFst(ordDict),
9393
(arg) => {
9494
if (arg === undefined) {
@@ -114,7 +114,7 @@ export function lookup<K, V>(
114114
key: K,
115115
map: Readonly<Map<K, V>>,
116116
): Maybe<V> {
117-
const lkup: undefined | [K, V] = LbAvlTree.lookup(ordOnFst(ordDict), [
117+
const lkup: undefined | [K, V] = PAvlTree.lookup(ordOnFst(ordDict), [
118118
key,
119119
null as V,
120120
], map.tree);
@@ -131,7 +131,7 @@ export function lookup<K, V>(
131131
* Complexity: `O(n)`
132132
*/
133133
export function toList<K, V>(map: Readonly<Map<K, V>>): [K, V][] {
134-
return LbAvlTree.toList(map.tree);
134+
return PAvlTree.toList(map.tree);
135135
}
136136

137137
/**
@@ -143,5 +143,5 @@ export function checkInvariants<K, V>(
143143
ordDict: Ord<K>,
144144
map: Readonly<Map<K, V>>,
145145
): void {
146-
return LbAvlTree.checkInvariants(ordOnFst(ordDict), map.tree);
146+
return PAvlTree.checkInvariants(ordOnFst(ordDict), map.tree);
147147
}

src/LambdaBuffers/Runtime/Maybe.ts renamed to src/Prelude/Runtime/Maybe.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as LbJson from "./Json.js";
1+
import * as PJson from "./Json.js";
22
import type { Eq } from "./Eq.js";
33
import type { Ord } from "./Ord.js";
44
import type { Json } from "./Json.js";
@@ -81,20 +81,20 @@ export function jsonMaybe<A>(dict: Json<A>): Json<Maybe<A>> {
8181
return {
8282
toJson: (maybe) => {
8383
if (maybe.name === "Nothing") {
84-
return LbJson.jsonConstructor("Nothing", []);
84+
return PJson.jsonConstructor("Nothing", []);
8585
} else {
86-
return LbJson.jsonConstructor("Just", [dict.toJson(maybe.fields)]);
86+
return PJson.jsonConstructor("Just", [dict.toJson(maybe.fields)]);
8787
}
8888
},
8989
fromJson: (value) => {
90-
return LbJson.caseJsonConstructor<Maybe<A>>("Prelude.Maybe", {
90+
return PJson.caseJsonConstructor<Maybe<A>>("Prelude.Maybe", {
9191
"Nothing": (ctorFields) => {
9292
if (ctorFields.length === 0) {
9393
return { name: "Nothing" };
9494
} else {
9595
throw new JsonError(
9696
"Expected JSON Array with 0 fields but got" +
97-
LbJson.stringify(value),
97+
PJson.stringify(value),
9898
);
9999
}
100100
},
@@ -104,7 +104,7 @@ export function jsonMaybe<A>(dict: Json<A>): Json<Maybe<A>> {
104104
} else {
105105
throw new JsonError(
106106
"Expected JSON Array with 1 fields but got" +
107-
LbJson.stringify(value),
107+
PJson.stringify(value),
108108
);
109109
}
110110
},
File renamed without changes.

0 commit comments

Comments
 (0)