@pithos/core 2.3.0 → 2.4.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.
Files changed (99) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/autocompletion.d.ts +129 -1
  3. package/dist/eidos/abstract-factory/abstract-factory.d.ts +125 -0
  4. package/dist/eidos/abstract-factory/abstract-factory.d.ts.map +1 -0
  5. package/dist/eidos/abstract-factory/abstract-factory.js +128 -0
  6. package/dist/eidos/abstract-factory/abstract-factory.js.map +1 -0
  7. package/dist/eidos/adapter/adapter.d.ts +97 -0
  8. package/dist/eidos/adapter/adapter.d.ts.map +1 -0
  9. package/dist/eidos/adapter/adapter.js +90 -0
  10. package/dist/eidos/adapter/adapter.js.map +1 -0
  11. package/dist/eidos/bridge/bridge.d.ts +81 -0
  12. package/dist/eidos/bridge/bridge.d.ts.map +1 -0
  13. package/dist/eidos/bridge/bridge.js +75 -0
  14. package/dist/eidos/bridge/bridge.js.map +1 -0
  15. package/dist/eidos/builder/builder.d.ts +181 -0
  16. package/dist/eidos/builder/builder.d.ts.map +1 -0
  17. package/dist/eidos/builder/builder.js +139 -0
  18. package/dist/eidos/builder/builder.js.map +1 -0
  19. package/dist/eidos/chain/chain.d.ts +99 -0
  20. package/dist/eidos/chain/chain.d.ts.map +1 -0
  21. package/dist/eidos/chain/chain.js +111 -0
  22. package/dist/eidos/chain/chain.js.map +1 -0
  23. package/dist/eidos/command/command.d.ts +267 -0
  24. package/dist/eidos/command/command.d.ts.map +1 -0
  25. package/dist/eidos/command/command.js +298 -0
  26. package/dist/eidos/command/command.js.map +1 -0
  27. package/dist/eidos/composite/composite.d.ts +168 -0
  28. package/dist/eidos/composite/composite.d.ts.map +1 -0
  29. package/dist/eidos/composite/composite.js +157 -0
  30. package/dist/eidos/composite/composite.js.map +1 -0
  31. package/dist/eidos/decorator/decorator.d.ts +138 -0
  32. package/dist/eidos/decorator/decorator.d.ts.map +1 -0
  33. package/dist/eidos/decorator/decorator.js +143 -0
  34. package/dist/eidos/decorator/decorator.js.map +1 -0
  35. package/dist/eidos/facade/facade.d.ts +61 -0
  36. package/dist/eidos/facade/facade.d.ts.map +1 -0
  37. package/dist/eidos/facade/facade.js +63 -0
  38. package/dist/eidos/facade/facade.js.map +1 -0
  39. package/dist/eidos/factory-method/factory-method.d.ts +76 -0
  40. package/dist/eidos/factory-method/factory-method.d.ts.map +1 -0
  41. package/dist/eidos/factory-method/factory-method.js +60 -0
  42. package/dist/eidos/factory-method/factory-method.js.map +1 -0
  43. package/dist/eidos/flyweight/flyweight.d.ts +40 -0
  44. package/dist/eidos/flyweight/flyweight.d.ts.map +1 -0
  45. package/dist/eidos/flyweight/flyweight.js +41 -0
  46. package/dist/eidos/flyweight/flyweight.js.map +1 -0
  47. package/dist/eidos/interpreter/interpreter.d.ts +82 -0
  48. package/dist/eidos/interpreter/interpreter.d.ts.map +1 -0
  49. package/dist/eidos/interpreter/interpreter.js +84 -0
  50. package/dist/eidos/interpreter/interpreter.js.map +1 -0
  51. package/dist/eidos/iterator/iterator.d.ts +164 -0
  52. package/dist/eidos/iterator/iterator.d.ts.map +1 -0
  53. package/dist/eidos/iterator/iterator.js +258 -0
  54. package/dist/eidos/iterator/iterator.js.map +1 -0
  55. package/dist/eidos/mediator/mediator.d.ts +102 -0
  56. package/dist/eidos/mediator/mediator.d.ts.map +1 -0
  57. package/dist/eidos/mediator/mediator.js +112 -0
  58. package/dist/eidos/mediator/mediator.js.map +1 -0
  59. package/dist/eidos/memento/memento.d.ts +103 -0
  60. package/dist/eidos/memento/memento.d.ts.map +1 -0
  61. package/dist/eidos/memento/memento.js +114 -0
  62. package/dist/eidos/memento/memento.js.map +1 -0
  63. package/dist/eidos/observer/observer.d.ts +96 -0
  64. package/dist/eidos/observer/observer.d.ts.map +1 -0
  65. package/dist/eidos/observer/observer.js +117 -0
  66. package/dist/eidos/observer/observer.js.map +1 -0
  67. package/dist/eidos/prototype/prototype.d.ts +32 -0
  68. package/dist/eidos/prototype/prototype.d.ts.map +1 -0
  69. package/dist/eidos/prototype/prototype.js +33 -0
  70. package/dist/eidos/prototype/prototype.js.map +1 -0
  71. package/dist/eidos/proxy/proxy.d.ts +108 -0
  72. package/dist/eidos/proxy/proxy.d.ts.map +1 -0
  73. package/dist/eidos/proxy/proxy.js +121 -0
  74. package/dist/eidos/proxy/proxy.js.map +1 -0
  75. package/dist/eidos/singleton/singleton.d.ts +76 -0
  76. package/dist/eidos/singleton/singleton.d.ts.map +1 -0
  77. package/dist/eidos/singleton/singleton.js +77 -0
  78. package/dist/eidos/singleton/singleton.js.map +1 -0
  79. package/dist/eidos/state/state.d.ts +152 -0
  80. package/dist/eidos/state/state.d.ts.map +1 -0
  81. package/dist/eidos/state/state.js +85 -0
  82. package/dist/eidos/state/state.js.map +1 -0
  83. package/dist/eidos/strategy/strategy.d.ts +148 -0
  84. package/dist/eidos/strategy/strategy.d.ts.map +1 -0
  85. package/dist/eidos/strategy/strategy.js +167 -0
  86. package/dist/eidos/strategy/strategy.js.map +1 -0
  87. package/dist/eidos/template/template.d.ts +95 -0
  88. package/dist/eidos/template/template.d.ts.map +1 -0
  89. package/dist/eidos/template/template.js +110 -0
  90. package/dist/eidos/template/template.js.map +1 -0
  91. package/dist/eidos/visitor/visitor.d.ts +78 -0
  92. package/dist/eidos/visitor/visitor.d.ts.map +1 -0
  93. package/dist/eidos/visitor/visitor.js +80 -0
  94. package/dist/eidos/visitor/visitor.js.map +1 -0
  95. package/dist/zygos/result/index.d.ts +19 -0
  96. package/dist/zygos/result/index.d.ts.map +1 -0
  97. package/dist/zygos/result/index.js +29 -0
  98. package/dist/zygos/result/index.js.map +1 -0
  99. package/package.json +28 -3
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Functional Facade Pattern.
3
+ *
4
+ * In OOP, the Facade pattern requires a class that encapsulates multiple
5
+ * subsystems and exposes a simplified interface to clients.
6
+ *
7
+ * In functional TypeScript, this is absorbed by the language:
8
+ * a facade is just a function that orchestrates other functions.
9
+ * No wrapper needed — it's what functions naturally do.
10
+ *
11
+ * This module exists for documentation and discoverability. The function is
12
+ * marked `@deprecated` to guide developers toward idiomatic functional code.
13
+ *
14
+ * @module eidos/facade
15
+ * @since 2.4.0
16
+ *
17
+ * @see {@link https://pithos.dev/api/eidos/facade/ | Explanations, examples and live demo}
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // No import needed — just write a function:
22
+ *
23
+ * // Subsystems (could be from different modules)
24
+ * const validateUser = (data: UserInput) => { ... };
25
+ * const hashPassword = (password: string) => { ... };
26
+ * const saveToDb = (user: User) => { ... };
27
+ * const sendWelcomeEmail = (email: string) => { ... };
28
+ *
29
+ * // Facade: simplified interface hiding the complexity
30
+ * const registerUser = async (data: UserInput) => {
31
+ * const validated = validateUser(data);
32
+ * const hashedPassword = await hashPassword(validated.password);
33
+ * const user = await saveToDb({ ...validated, password: hashedPassword });
34
+ * await sendWelcomeEmail(user.email);
35
+ * return user;
36
+ * };
37
+ *
38
+ * // Client only sees registerUser, not the subsystems
39
+ * await registerUser({ name: "Alice", email: "alice@example.com", password: "..." });
40
+ * ```
41
+ *
42
+ * @deprecated **Pattern absorbed by the language.**
43
+ *
44
+ * In functional TypeScript, a facade is just a function that calls other functions.
45
+ * This function is the identity — it exists only so you find this message.
46
+ *
47
+ * Write your facade directly:
48
+ * ```ts
49
+ * const checkout = (cart: Cart, payment: Payment) => {
50
+ * const validated = validateCart(cart);
51
+ * const charged = processPayment(payment, validated.total);
52
+ * const order = createOrder(validated, charged);
53
+ * sendConfirmation(order);
54
+ * return order;
55
+ * };
56
+ * ```
57
+ *
58
+ * @see {@link https://pithos.dev/api/eidos/facade/ | Full explanation, examples and live demo}
59
+ */
60
+ export function createFacade(fn) {
61
+ return fn;
62
+ }
63
+ //# sourceMappingURL=facade.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facade.js","sourceRoot":"","sources":["../../../src/eidos/facade/facade.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,MAAM,UAAU,YAAY,CAC1B,EAA6B;IAE7B,OAAO,EAAE,CAAC;AACZ,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Functional Factory Method Pattern.
3
+ *
4
+ * In OOP, the Factory Method pattern requires an abstract Creator class with
5
+ * an abstract `factoryMethod()`, and concrete subclasses that override it to
6
+ * produce different products. The Creator's business logic calls `factoryMethod()`
7
+ * without knowing which concrete product it will get.
8
+ *
9
+ * In functional TypeScript, this is just dependency injection: pass the factory
10
+ * as a parameter. The pattern is absorbed by the language — no wrapper needed.
11
+ *
12
+ * This module exists for documentation and discoverability. The function is
13
+ * marked `@deprecated` to guide developers toward idiomatic functional code.
14
+ *
15
+ * @module eidos/factory-method
16
+ * @since 2.4.0
17
+ *
18
+ * @see {@link https://pithos.dev/api/eidos/factory-method/ | Explanations, examples and live demo}
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // No import needed — just pass the factory as a parameter:
23
+ * type Product = { operation: () => string };
24
+ *
25
+ * const businessLogic = (createProduct: () => Product) => {
26
+ * const product = createProduct();
27
+ * return `Working with ${product.operation()}`;
28
+ * };
29
+ *
30
+ * // Different "concrete creators" are just different factory functions:
31
+ * const createProductA = (): Product => ({ operation: () => "ProductA" });
32
+ * const createProductB = (): Product => ({ operation: () => "ProductB" });
33
+ *
34
+ * businessLogic(createProductA); // "Working with ProductA"
35
+ * businessLogic(createProductB); // "Working with ProductB"
36
+ * ```
37
+ */
38
+ /**
39
+ * A Factory is a function that creates a product.
40
+ * This is just a type alias for documentation.
41
+ *
42
+ * @internal Not exported in API docs — use inline `() => T` instead
43
+ * @template T - The product type
44
+ * @since 2.4.0
45
+ */
46
+ export type Factory<T> = () => T;
47
+ /**
48
+ * A ParameterizedFactory creates products based on input parameters.
49
+ *
50
+ * @internal Not exported in API docs — use inline `(input: In) => T` instead
51
+ * @template In - The input/configuration type
52
+ * @template T - The product type
53
+ * @since 2.4.0
54
+ */
55
+ export type ParameterizedFactory<In, T> = (input: In) => T;
56
+ /**
57
+ * @deprecated **Pattern absorbed by the language.**
58
+ *
59
+ * In functional TypeScript, the Factory Method is just dependency injection.
60
+ * Pass the factory as a parameter — no wrapper needed.
61
+ *
62
+ * This function is the identity — it exists only so you find this message.
63
+ *
64
+ * Write your code directly:
65
+ * ```ts
66
+ * const process = (createProduct: () => Product) => {
67
+ * const product = createProduct();
68
+ * return product.doSomething();
69
+ * };
70
+ * ```
71
+ *
72
+ * @see {@link https://pithos.dev/api/eidos/factory-method/ | Full explanation, examples and live demo}
73
+ * @since 2.4.0
74
+ */
75
+ export declare function createFactoryMethod<T>(factory: () => T): () => T;
76
+ //# sourceMappingURL=factory-method.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory-method.d.ts","sourceRoot":"","sources":["../../../src/eidos/factory-method/factory-method.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH;;;;;;;GAOG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;AAEjC;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,CAEhE"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Functional Factory Method Pattern.
3
+ *
4
+ * In OOP, the Factory Method pattern requires an abstract Creator class with
5
+ * an abstract `factoryMethod()`, and concrete subclasses that override it to
6
+ * produce different products. The Creator's business logic calls `factoryMethod()`
7
+ * without knowing which concrete product it will get.
8
+ *
9
+ * In functional TypeScript, this is just dependency injection: pass the factory
10
+ * as a parameter. The pattern is absorbed by the language — no wrapper needed.
11
+ *
12
+ * This module exists for documentation and discoverability. The function is
13
+ * marked `@deprecated` to guide developers toward idiomatic functional code.
14
+ *
15
+ * @module eidos/factory-method
16
+ * @since 2.4.0
17
+ *
18
+ * @see {@link https://pithos.dev/api/eidos/factory-method/ | Explanations, examples and live demo}
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // No import needed — just pass the factory as a parameter:
23
+ * type Product = { operation: () => string };
24
+ *
25
+ * const businessLogic = (createProduct: () => Product) => {
26
+ * const product = createProduct();
27
+ * return `Working with ${product.operation()}`;
28
+ * };
29
+ *
30
+ * // Different "concrete creators" are just different factory functions:
31
+ * const createProductA = (): Product => ({ operation: () => "ProductA" });
32
+ * const createProductB = (): Product => ({ operation: () => "ProductB" });
33
+ *
34
+ * businessLogic(createProductA); // "Working with ProductA"
35
+ * businessLogic(createProductB); // "Working with ProductB"
36
+ * ```
37
+ */
38
+ /**
39
+ * @deprecated **Pattern absorbed by the language.**
40
+ *
41
+ * In functional TypeScript, the Factory Method is just dependency injection.
42
+ * Pass the factory as a parameter — no wrapper needed.
43
+ *
44
+ * This function is the identity — it exists only so you find this message.
45
+ *
46
+ * Write your code directly:
47
+ * ```ts
48
+ * const process = (createProduct: () => Product) => {
49
+ * const product = createProduct();
50
+ * return product.doSomething();
51
+ * };
52
+ * ```
53
+ *
54
+ * @see {@link https://pithos.dev/api/eidos/factory-method/ | Full explanation, examples and live demo}
55
+ * @since 2.4.0
56
+ */
57
+ export function createFactoryMethod(factory) {
58
+ return factory;
59
+ }
60
+ //# sourceMappingURL=factory-method.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factory-method.js","sourceRoot":"","sources":["../../../src/eidos/factory-method/factory-method.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAsBH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,mBAAmB,CAAI,OAAgB;IACrD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Functional Flyweight Pattern.
3
+ *
4
+ * In OOP, the Flyweight pattern requires separating intrinsic state (shared)
5
+ * from extrinsic state (unique), with a factory that caches and reuses objects
6
+ * with the same intrinsic state to minimize memory consumption.
7
+ *
8
+ * In functional TypeScript, this is memoization/caching. Arkhe provides
9
+ * `memoize` which caches function results based on arguments (the "intrinsic"
10
+ * state). The extrinsic state is passed at call time.
11
+ *
12
+ * This module re-exports `memoize` from Arkhe for discoverability.
13
+ *
14
+ * @module eidos/flyweight
15
+ * @since 2.4.0
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { memoize } from "@pithos/core/eidos/flyweight/flyweight";
20
+ * // or directly from Arkhe:
21
+ * import { memoize } from "../../arkhe/function/memoize.js";
22
+ *
23
+ * // Flyweight factory: creates/caches car configs by intrinsic state
24
+ * const getCarConfig = memoize((brand: string, model: string, color: string) => ({
25
+ * brand,
26
+ * model,
27
+ * color,
28
+ * // ... expensive computed properties
29
+ * }));
30
+ *
31
+ * // Extrinsic state (unique per instance) passed separately
32
+ * const car1 = { config: getCarConfig("BMW", "M5", "red"), plates: "ABC123", owner: "Alice" };
33
+ * const car2 = { config: getCarConfig("BMW", "M5", "red"), plates: "XYZ789", owner: "Bob" };
34
+ *
35
+ * // Same config object is reused (flyweight)
36
+ * car1.config === car2.config; // true
37
+ * ```
38
+ */
39
+ export { memoize } from "../../arkhe/function/memoize.js";
40
+ //# sourceMappingURL=flyweight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flyweight.d.ts","sourceRoot":"","sources":["../../../src/eidos/flyweight/flyweight.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Functional Flyweight Pattern.
3
+ *
4
+ * In OOP, the Flyweight pattern requires separating intrinsic state (shared)
5
+ * from extrinsic state (unique), with a factory that caches and reuses objects
6
+ * with the same intrinsic state to minimize memory consumption.
7
+ *
8
+ * In functional TypeScript, this is memoization/caching. Arkhe provides
9
+ * `memoize` which caches function results based on arguments (the "intrinsic"
10
+ * state). The extrinsic state is passed at call time.
11
+ *
12
+ * This module re-exports `memoize` from Arkhe for discoverability.
13
+ *
14
+ * @module eidos/flyweight
15
+ * @since 2.4.0
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { memoize } from "@pithos/core/eidos/flyweight/flyweight";
20
+ * // or directly from Arkhe:
21
+ * import { memoize } from "../../arkhe/function/memoize.js";
22
+ *
23
+ * // Flyweight factory: creates/caches car configs by intrinsic state
24
+ * const getCarConfig = memoize((brand: string, model: string, color: string) => ({
25
+ * brand,
26
+ * model,
27
+ * color,
28
+ * // ... expensive computed properties
29
+ * }));
30
+ *
31
+ * // Extrinsic state (unique per instance) passed separately
32
+ * const car1 = { config: getCarConfig("BMW", "M5", "red"), plates: "ABC123", owner: "Alice" };
33
+ * const car2 = { config: getCarConfig("BMW", "M5", "red"), plates: "XYZ789", owner: "Bob" };
34
+ *
35
+ * // Same config object is reused (flyweight)
36
+ * car1.config === car2.config; // true
37
+ * ```
38
+ */
39
+ // Re-export from Arkhe for discoverability
40
+ export { memoize } from "../../arkhe/function/memoize.js";
41
+ //# sourceMappingURL=flyweight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flyweight.js","sourceRoot":"","sources":["../../../src/eidos/flyweight/flyweight.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,2CAA2C;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Functional Interpreter Pattern.
3
+ *
4
+ * In OOP, the Interpreter pattern requires an Expression interface with
5
+ * `interpret(context)`, terminal expressions (literals), and non-terminal
6
+ * expressions (operators that combine other expressions).
7
+ *
8
+ * In functional TypeScript, this is absorbed by the combination of:
9
+ * - **Discriminated unions** for the AST (expression tree)
10
+ * - **Recursive functions** for evaluation (like Visitor's switch)
11
+ * - **Composite's fold** for tree traversal
12
+ *
13
+ * The pattern is essentially: define your grammar as types, write an
14
+ * evaluator function that pattern-matches on the AST.
15
+ *
16
+ * @module eidos/interpreter
17
+ * @since 2.4.0
18
+ *
19
+ * @see {@link https://pithos.dev/api/eidos/interpreter/ | Explanations, examples and live demo}
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * type Expr =
24
+ * | { type: "num"; value: number }
25
+ * | { type: "add"; left: Expr; right: Expr }
26
+ * | { type: "mul"; left: Expr; right: Expr };
27
+ *
28
+ * const evaluate = (expr: Expr): number => {
29
+ * switch (expr.type) {
30
+ * case "num": return expr.value;
31
+ * case "add": return evaluate(expr.left) + evaluate(expr.right);
32
+ * case "mul": return evaluate(expr.left) * evaluate(expr.right);
33
+ * }
34
+ * };
35
+ *
36
+ * // (5 + 3) * 2
37
+ * const expr: Expr = {
38
+ * type: "mul",
39
+ * left: { type: "add", left: { type: "num", value: 5 }, right: { type: "num", value: 3 } },
40
+ * right: { type: "num", value: 2 },
41
+ * };
42
+ *
43
+ * evaluate(expr); // 16
44
+ * ```
45
+ *
46
+ * @deprecated **Pattern absorbed by the language.**
47
+ *
48
+ * In TypeScript, the Interpreter pattern is just:
49
+ * 1. A discriminated union for your AST
50
+ * 2. A recursive function that switches on the `type` discriminant
51
+ *
52
+ * Instead of `interpret(expr, ctx, evaluator)`, call the evaluator directly:
53
+ *
54
+ * ```ts
55
+ * // Before (with interpret)
56
+ * const html = interpret(ast, ctx, evalNode);
57
+ *
58
+ * // After (just call it)
59
+ * const html = evalNode(ast, ctx);
60
+ * ```
61
+ *
62
+ * Minimal example:
63
+ *
64
+ * ```ts
65
+ * type Expr =
66
+ * | { type: "num"; value: number }
67
+ * | { type: "add"; left: Expr; right: Expr };
68
+ *
69
+ * const evaluate = (expr: Expr): number => {
70
+ * switch (expr.type) {
71
+ * case "num": return expr.value;
72
+ * case "add": return evaluate(expr.left) + evaluate(expr.right);
73
+ * }
74
+ * };
75
+ *
76
+ * evaluate({ type: "add", left: { type: "num", value: 5 }, right: { type: "num", value: 3 } }); // 8
77
+ * ```
78
+ *
79
+ * @see {@link https://pithos.dev/api/eidos/interpreter/ | Full explanation, examples and live Markdown interpreter demo}
80
+ */
81
+ export declare function interpret<Expr, Context, Result>(expr: Expr, ctx: Context, evaluator: (expr: Expr, ctx: Context) => Result): Result;
82
+ //# sourceMappingURL=interpreter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interpreter.d.ts","sourceRoot":"","sources":["../../../src/eidos/interpreter/interpreter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAC7C,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,KAAK,MAAM,GAC9C,MAAM,CAER"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Functional Interpreter Pattern.
3
+ *
4
+ * In OOP, the Interpreter pattern requires an Expression interface with
5
+ * `interpret(context)`, terminal expressions (literals), and non-terminal
6
+ * expressions (operators that combine other expressions).
7
+ *
8
+ * In functional TypeScript, this is absorbed by the combination of:
9
+ * - **Discriminated unions** for the AST (expression tree)
10
+ * - **Recursive functions** for evaluation (like Visitor's switch)
11
+ * - **Composite's fold** for tree traversal
12
+ *
13
+ * The pattern is essentially: define your grammar as types, write an
14
+ * evaluator function that pattern-matches on the AST.
15
+ *
16
+ * @module eidos/interpreter
17
+ * @since 2.4.0
18
+ *
19
+ * @see {@link https://pithos.dev/api/eidos/interpreter/ | Explanations, examples and live demo}
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * type Expr =
24
+ * | { type: "num"; value: number }
25
+ * | { type: "add"; left: Expr; right: Expr }
26
+ * | { type: "mul"; left: Expr; right: Expr };
27
+ *
28
+ * const evaluate = (expr: Expr): number => {
29
+ * switch (expr.type) {
30
+ * case "num": return expr.value;
31
+ * case "add": return evaluate(expr.left) + evaluate(expr.right);
32
+ * case "mul": return evaluate(expr.left) * evaluate(expr.right);
33
+ * }
34
+ * };
35
+ *
36
+ * // (5 + 3) * 2
37
+ * const expr: Expr = {
38
+ * type: "mul",
39
+ * left: { type: "add", left: { type: "num", value: 5 }, right: { type: "num", value: 3 } },
40
+ * right: { type: "num", value: 2 },
41
+ * };
42
+ *
43
+ * evaluate(expr); // 16
44
+ * ```
45
+ *
46
+ * @deprecated **Pattern absorbed by the language.**
47
+ *
48
+ * In TypeScript, the Interpreter pattern is just:
49
+ * 1. A discriminated union for your AST
50
+ * 2. A recursive function that switches on the `type` discriminant
51
+ *
52
+ * Instead of `interpret(expr, ctx, evaluator)`, call the evaluator directly:
53
+ *
54
+ * ```ts
55
+ * // Before (with interpret)
56
+ * const html = interpret(ast, ctx, evalNode);
57
+ *
58
+ * // After (just call it)
59
+ * const html = evalNode(ast, ctx);
60
+ * ```
61
+ *
62
+ * Minimal example:
63
+ *
64
+ * ```ts
65
+ * type Expr =
66
+ * | { type: "num"; value: number }
67
+ * | { type: "add"; left: Expr; right: Expr };
68
+ *
69
+ * const evaluate = (expr: Expr): number => {
70
+ * switch (expr.type) {
71
+ * case "num": return expr.value;
72
+ * case "add": return evaluate(expr.left) + evaluate(expr.right);
73
+ * }
74
+ * };
75
+ *
76
+ * evaluate({ type: "add", left: { type: "num", value: 5 }, right: { type: "num", value: 3 } }); // 8
77
+ * ```
78
+ *
79
+ * @see {@link https://pithos.dev/api/eidos/interpreter/ | Full explanation, examples and live Markdown interpreter demo}
80
+ */
81
+ export function interpret(expr, ctx, evaluator) {
82
+ return evaluator(expr, ctx);
83
+ }
84
+ //# sourceMappingURL=interpreter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interpreter.js","sourceRoot":"","sources":["../../../src/eidos/interpreter/interpreter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,MAAM,UAAU,SAAS,CACvB,IAAU,EACV,GAAY,EACZ,SAA+C;IAE/C,OAAO,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Functional Iterator Pattern.
3
+ *
4
+ * In OOP, the Iterator pattern requires a Collection interface, an Iterator
5
+ * interface, and concrete implementations that decouple traversal from the
6
+ * underlying data structure.
7
+ * In functional TypeScript, iterators are lazy sequences built on the native
8
+ * `Iterable` protocol, created via `createIterable` which decouples traversal
9
+ * logic from data sources.
10
+ *
11
+ * JavaScript already has the Iterator protocol (`Symbol.iterator`, `for...of`).
12
+ * The core of this module is the **constructor** layer:
13
+ * - `createIterable` - the GoF concept: decouple traversal from structure
14
+ * - `lazyRange` - lazy numeric sequences (finite or infinite)
15
+ * - `iterate` - unfold from a seed function
16
+ *
17
+ * A minimal set of **companion operators** (`map`, `filter`, `take`) and
18
+ * **consumers** (`toArray`, `reduce`) is included to make the constructors
19
+ * usable in practice (e.g. bounding an infinite `lazyRange` with `take`).
20
+ * These are not general-purpose collection utilities - they exist to serve
21
+ * the pattern.
22
+ *
23
+ * @module eidos/iterator
24
+ * @since 2.4.0
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { lazyRange, map, filter, take, toArray } from "@pithos/core/eidos/iterator/iterator";
29
+ *
30
+ * const result = toArray(
31
+ * take(5)(
32
+ * filter((n: number) => n % 2 === 0)(
33
+ * lazyRange(0, Infinity)
34
+ * )
35
+ * )
36
+ * );
37
+ * // [0, 2, 4, 6, 8]
38
+ * ```
39
+ */
40
+ import type { Option } from "../../zygos/option.js";
41
+ /**
42
+ * Creates a lazy, re-iterable sequence from a factory that produces a "next" function.
43
+ *
44
+ * The factory is called each time `[Symbol.iterator]()` is invoked, ensuring
45
+ * the iterable can be traversed multiple times. Each "next" call returns
46
+ * `Some(value)` for the next element or `None` to signal completion.
47
+ *
48
+ * This is the core of the GoF Iterator pattern: it decouples traversal logic
49
+ * (the `next` function) from the data source.
50
+ *
51
+ * @template T - The element type
52
+ * @param factory - A function that creates a stateful "next" supplier
53
+ * @returns A lazy Iterable
54
+ * @since 2.4.0
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * // Iterate over a tree in depth-first order
59
+ * const treeIter = createIterable(() => {
60
+ * const stack = [rootNode];
61
+ * return () => {
62
+ * if (stack.length === 0) return none;
63
+ * const node = stack.pop();
64
+ * if (!node) return none;
65
+ * stack.push(...node.children);
66
+ * return some(node.value);
67
+ * };
68
+ * });
69
+ *
70
+ * for (const value of treeIter) { ... }
71
+ * ```
72
+ */
73
+ export declare function createIterable<T>(factory: () => () => Option<T>): Iterable<T>;
74
+ /**
75
+ * Creates a lazy numeric range.
76
+ *
77
+ * Supports both ascending and descending ranges, as well as infinite ranges
78
+ * (use `take` to bound them).
79
+ *
80
+ * @param start - Start value (inclusive)
81
+ * @param end - End value (exclusive), defaults to Infinity
82
+ * @param step - Step increment, defaults to 1
83
+ * @returns A lazy Iterable of numbers
84
+ * @since 2.4.0
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * toArray(lazyRange(0, 5)); // [0, 1, 2, 3, 4]
89
+ * toArray(lazyRange(0, 10, 3)); // [0, 3, 6, 9]
90
+ * toArray(lazyRange(5, 0, -1)); // [5, 4, 3, 2, 1]
91
+ * ```
92
+ */
93
+ export declare function lazyRange(start: number, end?: number, step?: number): Iterable<number>;
94
+ /**
95
+ * Creates an infinite iterable by repeatedly applying a function to a seed.
96
+ *
97
+ * Produces: seed, f(seed), f(f(seed)), ...
98
+ *
99
+ * @template T - The element type
100
+ * @param seed - The initial value
101
+ * @param f - The function to apply repeatedly
102
+ * @returns An infinite lazy Iterable
103
+ * @since 2.4.0
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * // Powers of 2
108
+ * toArray(take(5)(iterate(1, (n) => n * 2))); // [1, 2, 4, 8, 16]
109
+ * ```
110
+ */
111
+ export declare function iterate<T>(seed: T, f: (value: T) => T): Iterable<T>;
112
+ /**
113
+ * Lazily transforms each element.
114
+ *
115
+ * @template A - Input element type
116
+ * @template B - Output element type
117
+ * @param f - The mapping function
118
+ * @returns A function that transforms an iterable
119
+ * @since 2.4.0
120
+ */
121
+ export declare function map<A, B>(f: (a: A) => B): (source: Iterable<A>) => Iterable<B>;
122
+ /**
123
+ * Lazily filters elements by a predicate.
124
+ *
125
+ * @template A - Element type
126
+ * @param predicate - The filter predicate
127
+ * @returns A function that filters an iterable
128
+ * @since 2.4.0
129
+ */
130
+ export declare function filter<A>(predicate: (a: A) => boolean): (source: Iterable<A>) => Iterable<A>;
131
+ /**
132
+ * Lazily takes the first n elements.
133
+ *
134
+ * Essential for bounding infinite iterables.
135
+ *
136
+ * @template A - Element type
137
+ * @param n - Number of elements to take
138
+ * @returns A function that limits an iterable
139
+ * @since 2.4.0
140
+ */
141
+ export declare function take<A>(n: number): (source: Iterable<A>) => Iterable<A>;
142
+ /**
143
+ * Collects all elements into an array.
144
+ *
145
+ * Do not use on infinite iterables without `take` first.
146
+ *
147
+ * @template A - Element type
148
+ * @param source - The iterable to collect
149
+ * @returns An array of all elements
150
+ * @since 2.4.0
151
+ */
152
+ export declare function toArray<A>(source: Iterable<A>): A[];
153
+ /**
154
+ * Reduces an iterable to a single value.
155
+ *
156
+ * @template A - Element type
157
+ * @template B - Accumulator type
158
+ * @param f - The reducer function
159
+ * @param seed - The initial accumulator
160
+ * @returns A function that reduces an iterable
161
+ * @since 2.4.0
162
+ */
163
+ export declare function reduce<A, B>(f: (acc: B, a: A) => B, seed: B): (source: Iterable<A>) => B;
164
+ //# sourceMappingURL=iterator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iterator.d.ts","sourceRoot":"","sources":["../../../src/eidos/iterator/iterator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAM5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,MAAM,MAAM,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAa7E;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,MAAM,EACb,GAAG,GAAE,MAAiB,EACtB,IAAI,GAAE,MAAU,GACf,QAAQ,CAAC,MAAM,CAAC,CAUlB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAanE;AAMD;;;;;;;;GAQG;AACH,wBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAU9E;AAED;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,OAAO,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAY5F;AAED;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAavE;AAMD;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAEnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAQxF"}