@zambit/elevate-ts 0.1.2

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 (170) hide show
  1. package/CLA-CORPORATE.md +72 -0
  2. package/CLA-INDIVIDUAL.md +71 -0
  3. package/DUAL-PUBLISHING-STRATEGY.md +571 -0
  4. package/LICENSE +610 -0
  5. package/README.md +77 -0
  6. package/dist/cjs/Either.d.ts +67 -0
  7. package/dist/cjs/Either.d.ts.map +1 -0
  8. package/dist/cjs/Either.js +147 -0
  9. package/dist/cjs/Either.js.map +1 -0
  10. package/dist/cjs/EitherAsync.d.ts +139 -0
  11. package/dist/cjs/EitherAsync.d.ts.map +1 -0
  12. package/dist/cjs/EitherAsync.js +171 -0
  13. package/dist/cjs/EitherAsync.js.map +1 -0
  14. package/dist/cjs/Function.d.ts +153 -0
  15. package/dist/cjs/Function.d.ts.map +1 -0
  16. package/dist/cjs/Function.js +110 -0
  17. package/dist/cjs/Function.js.map +1 -0
  18. package/dist/cjs/List.d.ts +134 -0
  19. package/dist/cjs/List.d.ts.map +1 -0
  20. package/dist/cjs/List.js +243 -0
  21. package/dist/cjs/List.js.map +1 -0
  22. package/dist/cjs/Maybe.d.ts +64 -0
  23. package/dist/cjs/Maybe.d.ts.map +1 -0
  24. package/dist/cjs/Maybe.js +122 -0
  25. package/dist/cjs/Maybe.js.map +1 -0
  26. package/dist/cjs/MaybeAsync.d.ts +115 -0
  27. package/dist/cjs/MaybeAsync.d.ts.map +1 -0
  28. package/dist/cjs/MaybeAsync.js +151 -0
  29. package/dist/cjs/MaybeAsync.js.map +1 -0
  30. package/dist/cjs/NonEmptyList.d.ts +86 -0
  31. package/dist/cjs/NonEmptyList.d.ts.map +1 -0
  32. package/dist/cjs/NonEmptyList.js +128 -0
  33. package/dist/cjs/NonEmptyList.js.map +1 -0
  34. package/dist/cjs/Reader.d.ts +53 -0
  35. package/dist/cjs/Reader.d.ts.map +1 -0
  36. package/dist/cjs/Reader.js +60 -0
  37. package/dist/cjs/Reader.js.map +1 -0
  38. package/dist/cjs/State.d.ts +71 -0
  39. package/dist/cjs/State.d.ts.map +1 -0
  40. package/dist/cjs/State.js +94 -0
  41. package/dist/cjs/State.js.map +1 -0
  42. package/dist/cjs/Tuple.d.ts +69 -0
  43. package/dist/cjs/Tuple.d.ts.map +1 -0
  44. package/dist/cjs/Tuple.js +73 -0
  45. package/dist/cjs/Tuple.js.map +1 -0
  46. package/dist/cjs/Validation.d.ts +53 -0
  47. package/dist/cjs/Validation.d.ts.map +1 -0
  48. package/dist/cjs/Validation.js +77 -0
  49. package/dist/cjs/Validation.js.map +1 -0
  50. package/dist/cjs/index.d.ts +12 -0
  51. package/dist/cjs/index.d.ts.map +1 -0
  52. package/dist/cjs/index.js +25 -0
  53. package/dist/cjs/index.js.map +1 -0
  54. package/dist/cjs/tokens/config.d.ts +43 -0
  55. package/dist/cjs/tokens/config.d.ts.map +1 -0
  56. package/dist/cjs/tokens/config.js +162 -0
  57. package/dist/cjs/tokens/config.js.map +1 -0
  58. package/dist/cjs/tokens/cssGen.d.ts +18 -0
  59. package/dist/cjs/tokens/cssGen.d.ts.map +1 -0
  60. package/dist/cjs/tokens/cssGen.js +144 -0
  61. package/dist/cjs/tokens/cssGen.js.map +1 -0
  62. package/dist/cjs/tokens/generateCSS.d.ts +18 -0
  63. package/dist/cjs/tokens/generateCSS.d.ts.map +1 -0
  64. package/dist/cjs/tokens/generateCSS.js +83 -0
  65. package/dist/cjs/tokens/generateCSS.js.map +1 -0
  66. package/dist/cjs/tokens/index.d.ts +13 -0
  67. package/dist/cjs/tokens/index.d.ts.map +1 -0
  68. package/dist/cjs/tokens/index.js +12 -0
  69. package/dist/cjs/tokens/index.js.map +1 -0
  70. package/dist/cjs/tsconfig.tsbuildinfo +1 -0
  71. package/dist/esm/Either.d.ts +67 -0
  72. package/dist/esm/Either.d.ts.map +1 -0
  73. package/dist/esm/Either.js +136 -0
  74. package/dist/esm/Either.js.map +1 -0
  75. package/dist/esm/EitherAsync.d.ts +139 -0
  76. package/dist/esm/EitherAsync.d.ts.map +1 -0
  77. package/dist/esm/EitherAsync.js +173 -0
  78. package/dist/esm/EitherAsync.js.map +1 -0
  79. package/dist/esm/Function.d.ts +153 -0
  80. package/dist/esm/Function.d.ts.map +1 -0
  81. package/dist/esm/Function.js +109 -0
  82. package/dist/esm/Function.js.map +1 -0
  83. package/dist/esm/List.d.ts +134 -0
  84. package/dist/esm/List.d.ts.map +1 -0
  85. package/dist/esm/List.js +243 -0
  86. package/dist/esm/List.js.map +1 -0
  87. package/dist/esm/Maybe.d.ts +64 -0
  88. package/dist/esm/Maybe.d.ts.map +1 -0
  89. package/dist/esm/Maybe.js +113 -0
  90. package/dist/esm/Maybe.js.map +1 -0
  91. package/dist/esm/MaybeAsync.d.ts +115 -0
  92. package/dist/esm/MaybeAsync.d.ts.map +1 -0
  93. package/dist/esm/MaybeAsync.js +150 -0
  94. package/dist/esm/MaybeAsync.js.map +1 -0
  95. package/dist/esm/NonEmptyList.d.ts +86 -0
  96. package/dist/esm/NonEmptyList.d.ts.map +1 -0
  97. package/dist/esm/NonEmptyList.js +128 -0
  98. package/dist/esm/NonEmptyList.js.map +1 -0
  99. package/dist/esm/Reader.d.ts +53 -0
  100. package/dist/esm/Reader.d.ts.map +1 -0
  101. package/dist/esm/Reader.js +60 -0
  102. package/dist/esm/Reader.js.map +1 -0
  103. package/dist/esm/State.d.ts +71 -0
  104. package/dist/esm/State.d.ts.map +1 -0
  105. package/dist/esm/State.js +94 -0
  106. package/dist/esm/State.js.map +1 -0
  107. package/dist/esm/Tuple.d.ts +69 -0
  108. package/dist/esm/Tuple.d.ts.map +1 -0
  109. package/dist/esm/Tuple.js +73 -0
  110. package/dist/esm/Tuple.js.map +1 -0
  111. package/dist/esm/Validation.d.ts +53 -0
  112. package/dist/esm/Validation.d.ts.map +1 -0
  113. package/dist/esm/Validation.js +79 -0
  114. package/dist/esm/Validation.js.map +1 -0
  115. package/dist/esm/index.d.ts +12 -0
  116. package/dist/esm/index.d.ts.map +1 -0
  117. package/dist/esm/index.js +22 -0
  118. package/dist/esm/index.js.map +1 -0
  119. package/dist/esm/src/Either.d.ts +67 -0
  120. package/dist/esm/src/Either.d.ts.map +1 -0
  121. package/dist/esm/src/Either.js +147 -0
  122. package/dist/esm/src/Either.js.map +1 -0
  123. package/dist/esm/src/EitherAsync.d.ts +139 -0
  124. package/dist/esm/src/EitherAsync.d.ts.map +1 -0
  125. package/dist/esm/src/EitherAsync.js +171 -0
  126. package/dist/esm/src/EitherAsync.js.map +1 -0
  127. package/dist/esm/src/Function.d.ts +153 -0
  128. package/dist/esm/src/Function.d.ts.map +1 -0
  129. package/dist/esm/src/Function.js +110 -0
  130. package/dist/esm/src/Function.js.map +1 -0
  131. package/dist/esm/src/List.d.ts +134 -0
  132. package/dist/esm/src/List.d.ts.map +1 -0
  133. package/dist/esm/src/List.js +243 -0
  134. package/dist/esm/src/List.js.map +1 -0
  135. package/dist/esm/src/Maybe.d.ts +64 -0
  136. package/dist/esm/src/Maybe.d.ts.map +1 -0
  137. package/dist/esm/src/Maybe.js +122 -0
  138. package/dist/esm/src/Maybe.js.map +1 -0
  139. package/dist/esm/src/MaybeAsync.d.ts +115 -0
  140. package/dist/esm/src/MaybeAsync.d.ts.map +1 -0
  141. package/dist/esm/src/MaybeAsync.js +151 -0
  142. package/dist/esm/src/MaybeAsync.js.map +1 -0
  143. package/dist/esm/src/NonEmptyList.d.ts +86 -0
  144. package/dist/esm/src/NonEmptyList.d.ts.map +1 -0
  145. package/dist/esm/src/NonEmptyList.js +128 -0
  146. package/dist/esm/src/NonEmptyList.js.map +1 -0
  147. package/dist/esm/src/Reader.d.ts +53 -0
  148. package/dist/esm/src/Reader.d.ts.map +1 -0
  149. package/dist/esm/src/Reader.js +60 -0
  150. package/dist/esm/src/Reader.js.map +1 -0
  151. package/dist/esm/src/State.d.ts +71 -0
  152. package/dist/esm/src/State.d.ts.map +1 -0
  153. package/dist/esm/src/State.js +94 -0
  154. package/dist/esm/src/State.js.map +1 -0
  155. package/dist/esm/src/Tuple.d.ts +69 -0
  156. package/dist/esm/src/Tuple.d.ts.map +1 -0
  157. package/dist/esm/src/Tuple.js +73 -0
  158. package/dist/esm/src/Tuple.js.map +1 -0
  159. package/dist/esm/src/Validation.d.ts +53 -0
  160. package/dist/esm/src/Validation.d.ts.map +1 -0
  161. package/dist/esm/src/Validation.js +77 -0
  162. package/dist/esm/src/Validation.js.map +1 -0
  163. package/dist/esm/src/index.d.ts +12 -0
  164. package/dist/esm/src/index.d.ts.map +1 -0
  165. package/dist/esm/src/index.js +25 -0
  166. package/dist/esm/src/index.js.map +1 -0
  167. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
  168. package/elevate-ts-vs-effect-critique.md +806 -0
  169. package/eslint.config.js +104 -0
  170. package/package.json +139 -0
@@ -0,0 +1,150 @@
1
+ // MaybeAsync — Lazy Async Maybe
2
+ import * as Maybe from './Maybe.js';
3
+ /**
4
+ * Construct a MaybeAsync from a lazy computation.
5
+ * @param run - A function returning Promise<Maybe<A>>.
6
+ * @returns A MaybeAsync that encapsulates the computation.
7
+ */
8
+ export const MaybeAsync = (run) => ({ tag: 'MaybeAsync', run });
9
+ /**
10
+ * Lift a synchronous Maybe into MaybeAsync.
11
+ * @param ma - The synchronous Maybe.
12
+ * @returns A MaybeAsync that immediately resolves to the Maybe.
13
+ */
14
+ export const liftMaybe = (ma) => MaybeAsync(() => Promise.resolve(ma));
15
+ /**
16
+ * Lift a Promise into MaybeAsync.
17
+ * Any rejected Promise or thrown error becomes Nothing; never rejects.
18
+ * @param p - The Promise to lift.
19
+ * @returns A MaybeAsync that resolves to Just the value or Nothing on error.
20
+ */
21
+ export const fromPromise = (p) => MaybeAsync(() => p.then((a) => Maybe.Just(a)).catch(() => Maybe.Nothing));
22
+ /**
23
+ * Wrap an async function with error handling.
24
+ * Any rejected Promise or thrown error becomes Nothing; never rejects.
25
+ * @param f - An async function.
26
+ * @returns A MaybeAsync that captures the result or Nothing on error.
27
+ */
28
+ export const tryCatch = (f) => MaybeAsync(() => Promise.resolve().then(() => f()).then((a) => Maybe.Just(a)).catch(() => Maybe.Nothing));
29
+ /**
30
+ * Functor map over the value.
31
+ * Any rejected Promise or thrown error becomes Nothing; never rejects.
32
+ * @param f - Function to transform the value.
33
+ * @returns A function taking MaybeAsync and returning a new MaybeAsync.
34
+ */
35
+ export const map = (f) => (ma) => MaybeAsync(() => ma.run().then((maybe) => Maybe.map(f)(maybe)));
36
+ /**
37
+ * Monadic bind: sequentially compose MaybeAsync computations.
38
+ * Any rejected Promise or thrown error becomes Nothing; never rejects.
39
+ * @param f - Function that returns a MaybeAsync.
40
+ * @returns A function taking MaybeAsync and returning a flattened MaybeAsync.
41
+ */
42
+ export const chain = (f) => (ma) => MaybeAsync(async () => {
43
+ const maybe = await ma.run();
44
+ if (maybe.tag === 'Just') {
45
+ return f(maybe.value).run();
46
+ }
47
+ return Maybe.Nothing;
48
+ });
49
+ /**
50
+ * Applicative ap: apply a MaybeAsync function to a MaybeAsync value.
51
+ * Any rejected Promise or thrown error becomes Nothing; never rejects.
52
+ * @param mf - A MaybeAsync of a function.
53
+ * @returns A function taking MaybeAsync and returning a new MaybeAsync.
54
+ */
55
+ export const ap = (mf) => (ma) => MaybeAsync(async () => {
56
+ const [f, a] = await Promise.all([mf.run(), ma.run()]);
57
+ return Maybe.ap(f)(a);
58
+ });
59
+ /**
60
+ * Alt: use alternative MaybeAsync if first is Nothing.
61
+ * Any rejected Promise or thrown error becomes Nothing; never rejects.
62
+ * @param alt_ma - The alternative MaybeAsync.
63
+ * @returns A function taking the primary MaybeAsync.
64
+ */
65
+ export const alt = (alt_ma) => (ma) => MaybeAsync(async () => {
66
+ const maybe = await ma.run();
67
+ if (maybe.tag === 'Just')
68
+ return maybe;
69
+ return alt_ma.run();
70
+ });
71
+ /**
72
+ * Keep the value if predicate holds, otherwise Nothing.
73
+ * Any rejected Promise or thrown error becomes Nothing; never rejects.
74
+ * @param predicate - The predicate to test.
75
+ * @returns A function taking MaybeAsync and returning filtered MaybeAsync.
76
+ */
77
+ export const filter = (predicate) => (ma) => MaybeAsync(() => ma.run().then((maybe) => Maybe.filter(predicate)(maybe)));
78
+ /**
79
+ * Extract the value or provide a default.
80
+ * Any rejected Promise or thrown error becomes Nothing; never rejects.
81
+ * @param a - The default value.
82
+ * @returns A function taking MaybeAsync and returning a Promise of the value.
83
+ */
84
+ export const getOrElse = (a) => (ma) => ma.run().then((maybe) => Maybe.getOrElse(a)(maybe));
85
+ /**
86
+ * Extract the value or compute a default lazily.
87
+ * Any rejected Promise or thrown error becomes Nothing; never rejects.
88
+ * @param f - A function computing the default.
89
+ * @returns A function taking MaybeAsync and returning a Promise of the value.
90
+ */
91
+ export const getOrElseL = (f) => (ma) => ma.run().then(async (maybe) => {
92
+ if (maybe.tag === 'Just')
93
+ return maybe.value;
94
+ return f();
95
+ });
96
+ /**
97
+ * Convert MaybeAsync to EitherAsync.
98
+ * Any rejected Promise or thrown error becomes Nothing which becomes Left; never rejects.
99
+ * @param onNothing - The Left value if Nothing.
100
+ * @returns A function taking MaybeAsync and returning EitherAsync.
101
+ */
102
+ export const toEitherAsync = (onNothing) => (ma) => {
103
+ // Dynamic import to avoid circular dependencies
104
+ return {
105
+ tag: 'EitherAsync',
106
+ run: async () => {
107
+ const maybe = await ma.run();
108
+ const Either = (await import('./Either.js'));
109
+ return maybe.tag === 'Just'
110
+ ? Either.Right(maybe.value)
111
+ : Either.Left(onNothing);
112
+ },
113
+ };
114
+ };
115
+ /**
116
+ * Case analysis on MaybeAsync.
117
+ * Any rejected Promise or thrown error becomes Nothing; never rejects.
118
+ * @param onNothing - Value for Nothing.
119
+ * @param onJust - Function for Just value.
120
+ * @returns A function taking MaybeAsync and returning Promise of result.
121
+ */
122
+ export const fold = (onNothing, onJust) => (ma) => ma.run().then(async (maybe) => {
123
+ if (maybe.tag === 'Just')
124
+ return onJust(maybe.value);
125
+ return onNothing;
126
+ });
127
+ /**
128
+ * Collect Just values from an array of MaybeAsync.
129
+ * Rejected Promises and errors are filtered out.
130
+ * @param maybes - Array of MaybeAsync.
131
+ * @returns Promise of collected values.
132
+ */
133
+ export const catMaybes = (maybes) => Promise.all(maybes.map((m) => m.run())).then((results) => results.flatMap((maybe) => (maybe.tag === 'Just' ? [maybe.value] : [])));
134
+ /**
135
+ * All-or-Nothing: if any MaybeAsync is Nothing, result is Nothing.
136
+ * Any rejected Promise or thrown error becomes Nothing; never rejects.
137
+ * @param maybes - Array of MaybeAsync.
138
+ * @returns A MaybeAsync that is Just of array if all are Just, else Nothing.
139
+ */
140
+ export const all = (maybes) => MaybeAsync(async () => {
141
+ const results = await Promise.all(maybes.map((m) => m.run()));
142
+ const values = [];
143
+ for (const maybe of results) {
144
+ if (maybe.tag === 'Nothing')
145
+ return Maybe.Nothing;
146
+ values.push(maybe.value);
147
+ }
148
+ return Maybe.Just(values);
149
+ });
150
+ //# sourceMappingURL=MaybeAsync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MaybeAsync.js","sourceRoot":"","sources":["../../src/MaybeAsync.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAEhC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAYnC;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,GAAkC,EACnB,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,CAAA;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAI,EAAkB,EAAiB,EAAE,CAChE,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAA;AAEvC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAI,CAAa,EAAiB,EAAE,CAC7D,UAAU,CAAC,GAAG,EAAE,CACd,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,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T,EAAE,CACzB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CACvD,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CACxE,CAAA;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,CAAI,MAAgC,EAAmB,EAAE,CAC1E,UAAU,CAAC,KAAK,IAAI,EAAE;IACpB,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;IAC7D,MAAM,MAAM,GAAQ,EAAE,CAAA;IACtB,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,CAAC,GAAG,KAAK,SAAS;YAAE,OAAO,KAAK,CAAC,OAAO,CAAA;QACjD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAC1B,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AAC3B,CAAC,CAAC,CAAA"}
@@ -0,0 +1,86 @@
1
+ import * as Maybe from './Maybe.js';
2
+ declare const NonEmptyListBrand: unique symbol;
3
+ /** Branded nonempty list type: at least one element guaranteed. */
4
+ export type NonEmptyList<A> = readonly [A, ...A[]] & {
5
+ readonly [NonEmptyListBrand]: true;
6
+ };
7
+ /**
8
+ * Safely lift an array to NonEmptyList if nonempty.
9
+ * @param arr - The array to lift.
10
+ * @returns Just the NonEmptyList if nonempty, Nothing if empty.
11
+ */
12
+ export declare const fromArray: <A>(arr: readonly A[]) => Maybe.Maybe<NonEmptyList<A>>;
13
+ /**
14
+ * Unsafely cast an array to NonEmptyList without checking.
15
+ * @param arr - An array (assumed nonempty).
16
+ * @returns The array cast as NonEmptyList.
17
+ */
18
+ export declare const fromArrayUnsafe: <A>(arr: readonly A[]) => NonEmptyList<A>;
19
+ /**
20
+ * Convert a NonEmptyList back to a plain array.
21
+ * @param nel - The nonempty list.
22
+ * @returns A readonly array.
23
+ */
24
+ export declare const toArray: <A>(nel: NonEmptyList<A>) => readonly A[];
25
+ /**
26
+ * Extract the first element (guaranteed to exist).
27
+ * @param nel - The nonempty list.
28
+ * @returns The first element.
29
+ */
30
+ export declare const head: <A>(nel: NonEmptyList<A>) => A;
31
+ /**
32
+ * Extract all elements after the first.
33
+ * @param nel - The nonempty list.
34
+ * @returns An array of remaining elements (may be empty).
35
+ */
36
+ export declare const tail: <A>(nel: NonEmptyList<A>) => readonly A[];
37
+ /**
38
+ * Extract the last element.
39
+ * @param nel - The nonempty list.
40
+ * @returns The last element.
41
+ */
42
+ export declare const last: <A>(nel: NonEmptyList<A>) => A;
43
+ /**
44
+ * Extract all elements except the last.
45
+ * @param nel - The nonempty list.
46
+ * @returns An array of all but the last element.
47
+ */
48
+ export declare const init: <A>(nel: NonEmptyList<A>) => readonly A[];
49
+ /**
50
+ * Functor map over a NonEmptyList.
51
+ * @param f - Function to transform each element.
52
+ * @returns A function that takes a NonEmptyList and returns a new NonEmptyList.
53
+ */
54
+ export declare const map: <A, B>(f: (a: A) => B) => ((nel: NonEmptyList<A>) => NonEmptyList<B>);
55
+ /**
56
+ * Applicative ap: apply a NonEmptyList of functions to a NonEmptyList of values.
57
+ * @param nf - A NonEmptyList of functions.
58
+ * @returns A function that takes a NonEmptyList and returns a new NonEmptyList.
59
+ */
60
+ export declare const ap: <A, B>(nf: NonEmptyList<(a: A) => B>) => ((nel: NonEmptyList<A>) => NonEmptyList<B>);
61
+ /**
62
+ * Monadic bind: sequentially compose NonEmptyList computations.
63
+ * @param f - Function that returns a NonEmptyList.
64
+ * @returns A function that takes a NonEmptyList and returns a flattened NonEmptyList.
65
+ */
66
+ export declare const chain: <A, B>(f: (a: A) => NonEmptyList<B>) => ((nel: NonEmptyList<A>) => NonEmptyList<B>);
67
+ /**
68
+ * Concatenate two nonempty lists.
69
+ * @param nel2 - The second nonempty list.
70
+ * @returns A function that takes the first nonempty list and returns their concatenation.
71
+ */
72
+ export declare const concat: <A>(nel2: NonEmptyList<A>) => ((nel1: NonEmptyList<A>) => NonEmptyList<A>);
73
+ /**
74
+ * Find the minimum element using a comparator.
75
+ * @param ord - Comparator function (returns negative if first < second, positive if first > second).
76
+ * @returns A function that takes a NonEmptyList and returns the minimum element.
77
+ */
78
+ export declare const min: <A>(ord: (a: A, b: A) => number) => ((nel: NonEmptyList<A>) => A);
79
+ /**
80
+ * Find the maximum element using a comparator.
81
+ * @param ord - Comparator function (returns negative if first < second, positive if first > second).
82
+ * @returns A function that takes a NonEmptyList and returns the maximum element.
83
+ */
84
+ export declare const max: <A>(ord: (a: A, b: A) => number) => ((nel: NonEmptyList<A>) => A);
85
+ export {};
86
+ //# sourceMappingURL=NonEmptyList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NonEmptyList.d.ts","sourceRoot":"","sources":["../../src/NonEmptyList.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AAEnC,OAAO,CAAC,MAAM,iBAAiB,EAAE,OAAO,MAAM,CAAA;AAE9C,mEAAmE;AACnE,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG;IACnD,QAAQ,CAAC,CAAC,iBAAiB,CAAC,EAAE,IAAI,CAAA;CACnC,CAAA;AAUD;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,KAAK,SAAS,CAAC,EAAE,KAAG,KAAK,CAAC,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G,CAAC,CAAC,EAAE,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,KAAG,CAAC,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,CAU/E,CAAA;AAEH;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAChB,CAAC,EAAE,MAAM,YAAY,CAAC,CAAC,CAAC,KAAG,CAAC,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,YAAY,CAAC,CAAC,CAAC,CAEtC,CAAA;AAEnC;;;;GAIG;AACH,eAAO,MAAM,GAAG,GACb,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,KAAG,CAAC,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAS7D,CAAA;AAEH;;;;GAIG;AACH,eAAO,MAAM,GAAG,GACb,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,MAAM,KAAG,CAAC,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,CAS7D,CAAA"}
@@ -0,0 +1,128 @@
1
+ // NonEmptyList — Guaranteed Nonempty Arrays (branded type)
2
+ import * as Maybe from './Maybe.js';
3
+ /**
4
+ * Unsafely cast an array to NonEmptyList.
5
+ * @param arr - An array (must be nonempty at runtime).
6
+ * @returns The array cast as NonEmptyList.
7
+ */
8
+ const unsafeBrand = (arr) => arr;
9
+ /**
10
+ * Safely lift an array to NonEmptyList if nonempty.
11
+ * @param arr - The array to lift.
12
+ * @returns Just the NonEmptyList if nonempty, Nothing if empty.
13
+ */
14
+ export const fromArray = (arr) => arr.length > 0 ? Maybe.Just(unsafeBrand(arr)) : Maybe.Nothing;
15
+ /**
16
+ * Unsafely cast an array to NonEmptyList without checking.
17
+ * @param arr - An array (assumed nonempty).
18
+ * @returns The array cast as NonEmptyList.
19
+ */
20
+ export const fromArrayUnsafe = (arr) => unsafeBrand(arr);
21
+ /**
22
+ * Convert a NonEmptyList back to a plain array.
23
+ * @param nel - The nonempty list.
24
+ * @returns A readonly array.
25
+ */
26
+ export const toArray = (nel) => nel;
27
+ /**
28
+ * Extract the first element (guaranteed to exist).
29
+ * @param nel - The nonempty list.
30
+ * @returns The first element.
31
+ */
32
+ export const head = (nel) => nel[0];
33
+ /**
34
+ * Extract all elements after the first.
35
+ * @param nel - The nonempty list.
36
+ * @returns An array of remaining elements (may be empty).
37
+ */
38
+ export const tail = (nel) => nel.slice(1);
39
+ /**
40
+ * Extract the last element.
41
+ * @param nel - The nonempty list.
42
+ * @returns The last element.
43
+ */
44
+ export const last = (nel) => nel[nel.length - 1];
45
+ /**
46
+ * Extract all elements except the last.
47
+ * @param nel - The nonempty list.
48
+ * @returns An array of all but the last element.
49
+ */
50
+ export const init = (nel) => nel.slice(0, -1);
51
+ /**
52
+ * Functor map over a NonEmptyList.
53
+ * @param f - Function to transform each element.
54
+ * @returns A function that takes a NonEmptyList and returns a new NonEmptyList.
55
+ */
56
+ export const map = (f) => (nel) => unsafeBrand(nel.map(f));
57
+ /**
58
+ * Applicative ap: apply a NonEmptyList of functions to a NonEmptyList of values.
59
+ * @param nf - A NonEmptyList of functions.
60
+ * @returns A function that takes a NonEmptyList and returns a new NonEmptyList.
61
+ */
62
+ export const ap = (nf) => (nel) => {
63
+ const result = [];
64
+ for (const f of nf) {
65
+ for (const a of nel) {
66
+ result.push(f(a));
67
+ }
68
+ }
69
+ return unsafeBrand(result);
70
+ };
71
+ /**
72
+ * Monadic bind: sequentially compose NonEmptyList computations.
73
+ * @param f - Function that returns a NonEmptyList.
74
+ * @returns A function that takes a NonEmptyList and returns a flattened NonEmptyList.
75
+ */
76
+ export const chain = (f) => (nel) => {
77
+ const result = [];
78
+ for (const a of nel) {
79
+ const bs = f(a);
80
+ for (const b of bs) {
81
+ result.push(b);
82
+ }
83
+ }
84
+ return unsafeBrand(result);
85
+ };
86
+ /**
87
+ * Concatenate two nonempty lists.
88
+ * @param nel2 - The second nonempty list.
89
+ * @returns A function that takes the first nonempty list and returns their concatenation.
90
+ */
91
+ export const concat = (nel2) => (nel1) => unsafeBrand([...nel1, ...nel2]);
92
+ /**
93
+ * Find the minimum element using a comparator.
94
+ * @param ord - Comparator function (returns negative if first < second, positive if first > second).
95
+ * @returns A function that takes a NonEmptyList and returns the minimum element.
96
+ */
97
+ export const min = (ord) => (nel) => {
98
+ let result = nel[0];
99
+ for (let i = 1; i < nel.length; i++) {
100
+ if (ord(nel[i], result) < 0) {
101
+ result = nel[i];
102
+ }
103
+ }
104
+ return result;
105
+ };
106
+ /**
107
+ * Find the maximum element using a comparator.
108
+ * @param ord - Comparator function (returns negative if first < second, positive if first > second).
109
+ * @returns A function that takes a NonEmptyList and returns the maximum element.
110
+ */
111
+ export const max = (ord) => (nel) => {
112
+ let result = nel[0];
113
+ for (let i = 1; i < nel.length; i++) {
114
+ if (ord(nel[i], result) > 0) {
115
+ result = nel[i];
116
+ }
117
+ }
118
+ return result;
119
+ };
120
+ // Fantasy Land symbols
121
+ // Note: FL methods excluded to work around vitest coverage serialization issues.
122
+ // The core functionality is complete and all point-free functions work correctly.
123
+ // TODO: Re-enable Fantasy Land methods when vitest issue is resolved.
124
+ //
125
+ // const nelProto = Object.getPrototypeOf(unsafeBrand([0]))
126
+ // nelProto['fantasy-land/map'] = ...
127
+ // etc.
128
+ //# sourceMappingURL=NonEmptyList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NonEmptyList.js","sourceRoot":"","sources":["../../src/NonEmptyList.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAE3D,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AASnC;;;;GAIG;AACH,MAAM,WAAW,GAAG,CAAI,GAAiB,EAAmB,EAAE,CAC5D,GAAsB,CAAA;AAExB;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAI,GAAiB,EAAgC,EAA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AAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,GAAG,GACd,CAAI,GAA2B,EAAiC,EAAE,CAClE,CAAC,GAAG,EAAE,EAAE;IACN,IAAI,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;IACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YAC5B,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAEH,uBAAuB;AACvB,iFAAiF;AACjF,kFAAkF;AAClF,sEAAsE;AACtE,EAAE;AACF,2DAA2D;AAC3D,qCAAqC;AACrC,OAAO"}
@@ -0,0 +1,53 @@
1
+ /** Represents a Reader computation: a pure function (env: R) => A. */
2
+ export type Reader<R, A> = {
3
+ readonly tag: 'Reader';
4
+ readonly run: (env: R) => A;
5
+ };
6
+ /**
7
+ * Construct a Reader from a function.
8
+ * @param run - The function that reads the environment.
9
+ * @returns A Reader that encapsulates the function.
10
+ */
11
+ export declare const Reader: <R, A>(run: (env: R) => A) => Reader<R, A>;
12
+ /**
13
+ * Retrieve the environment as a value.
14
+ * @returns A Reader that returns the environment unchanged.
15
+ */
16
+ export declare const ask: <R>() => Reader<R, R>;
17
+ /**
18
+ * Retrieve and transform the environment.
19
+ * @param f - Function to transform the environment.
20
+ * @returns A Reader that applies the function to the environment.
21
+ */
22
+ export declare const asks: <R, A>(f: (env: R) => A) => Reader<R, A>;
23
+ /**
24
+ * Modify the environment for a sub-computation.
25
+ * @param f - Function to transform the environment.
26
+ * @returns A function that takes a Reader and returns a new Reader with modified environment.
27
+ */
28
+ export declare const local: <R>(f: (env: R) => R) => (<A>(reader: Reader<R, A>) => Reader<R, A>);
29
+ /**
30
+ * Functor map over the result.
31
+ * @param f - Function to transform the value.
32
+ * @returns A function that takes a Reader and returns a new Reader with mapped value.
33
+ */
34
+ export declare const map: <A, B>(f: (a: A) => B) => (<R>(reader: Reader<R, A>) => Reader<R, B>);
35
+ /**
36
+ * Applicative ap: apply a Reader containing a function to a Reader containing a value.
37
+ * @param rf - A Reader containing a function.
38
+ * @returns A function that takes a Reader and returns a new Reader with applied function.
39
+ */
40
+ export declare const ap: <R, A, B>(rf: Reader<R, (a: A) => B>) => ((ra: Reader<R, A>) => Reader<R, B>);
41
+ /**
42
+ * Monadic bind: sequentially compose two Readers.
43
+ * @param f - Function that returns a new Reader.
44
+ * @returns A function that takes a Reader and returns a new Reader.
45
+ */
46
+ export declare const chain: <R, A, B>(f: (a: A) => Reader<R, B>) => ((reader: Reader<R, A>) => Reader<R, B>);
47
+ /**
48
+ * Execute a Reader with an environment.
49
+ * @param env - The environment to provide.
50
+ * @returns A function that takes a Reader and returns its result.
51
+ */
52
+ export declare const runReader: <R, A>(env: R) => ((reader: Reader<R, A>) => A);
53
+ //# sourceMappingURL=Reader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Reader.d.ts","sourceRoot":"","sources":["../../src/Reader.ts"],"names":[],"mappings":"AAEA,sEAAsE;AACtE,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI;IAAE,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAA;CAAE,CAAA;AAElF;;;;GAIG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,KAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAG3D,CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC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AAA;AAEhD;;;;GAIG;AACH,eAAO,MAAM,SAAS,GACnB,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,KAAG,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAE3B,CAAA"}
@@ -0,0 +1,60 @@
1
+ // Reader — Dependency Injection
2
+ /**
3
+ * Construct a Reader from a function.
4
+ * @param run - The function that reads the environment.
5
+ * @returns A Reader that encapsulates the function.
6
+ */
7
+ export const Reader = (run) => ({
8
+ tag: 'Reader',
9
+ run,
10
+ });
11
+ /**
12
+ * Retrieve the environment as a value.
13
+ * @returns A Reader that returns the environment unchanged.
14
+ */
15
+ export const ask = () => Reader((env) => env);
16
+ /**
17
+ * Retrieve and transform the environment.
18
+ * @param f - Function to transform the environment.
19
+ * @returns A Reader that applies the function to the environment.
20
+ */
21
+ export const asks = (f) => Reader(f);
22
+ /**
23
+ * Modify the environment for a sub-computation.
24
+ * @param f - Function to transform the environment.
25
+ * @returns A function that takes a Reader and returns a new Reader with modified environment.
26
+ */
27
+ export const local = (f) => (reader) => Reader((env) => reader.run(f(env)));
28
+ /**
29
+ * Functor map over the result.
30
+ * @param f - Function to transform the value.
31
+ * @returns A function that takes a Reader and returns a new Reader with mapped value.
32
+ */
33
+ export const map = (f) => (reader) => Reader((env) => f(reader.run(env)));
34
+ /**
35
+ * Applicative ap: apply a Reader containing a function to a Reader containing a value.
36
+ * @param rf - A Reader containing a function.
37
+ * @returns A function that takes a Reader and returns a new Reader with applied function.
38
+ */
39
+ export const ap = (rf) => (ra) => Reader((env) => rf.run(env)(ra.run(env)));
40
+ /**
41
+ * Monadic bind: sequentially compose two Readers.
42
+ * @param f - Function that returns a new Reader.
43
+ * @returns A function that takes a Reader and returns a new Reader.
44
+ */
45
+ export const chain = (f) => (reader) => Reader((env) => f(reader.run(env)).run(env));
46
+ /**
47
+ * Execute a Reader with an environment.
48
+ * @param env - The environment to provide.
49
+ * @returns A function that takes a Reader and returns its result.
50
+ */
51
+ export const runReader = (env) => (reader) => reader.run(env);
52
+ // Fantasy Land symbols
53
+ // Note: FL methods excluded to work around vitest coverage serialization issues.
54
+ // The core functionality is complete and all point-free functions work correctly.
55
+ // TODO: Re-enable Fantasy Land methods when vitest issue is resolved.
56
+ //
57
+ // const readerProto = Object.getPrototypeOf(Reader(() => 0))
58
+ // readerProto['fantasy-land/map'] = ...
59
+ // etc.
60
+ //# sourceMappingURL=Reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Reader.js","sourceRoot":"","sources":["../../src/Reader.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAKhC;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CAAO,GAAkB,EAAgB,EAAE,CAAC,CAAC;IACjE,GAAG,EAAE,QAAQ;IACb,GAAG;CACJ,CAAC,CAAA;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,GAAoB,EAAE,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAA;AAE9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAAG,CAAO,CAAgB,EAAgB,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;AAEvE;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAChB,CAAI,CAAgB,EAA+C,EAAE,CACrE,CAAC,MAAM,EAAE,EAAE,CACT,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,GAAG,GACd,CAAO,CAAc,EAA+C,EAAE,CACtE,CAAC,MAAM,EAAE,EAAE,CACT,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,EAAE,GACb,CAAU,EAA0B,EAAwC,EAAE,CAC9E,CAAC,EAAE,EAAE,EAAE,CACL,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAE7C;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAChB,CAAU,CAAyB,EAA4C,EAAE,CACjF,CAAC,MAAM,EAAE,EAAE,CACT,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;AAEhD;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GACpB,CAAO,GAAM,EAAiC,EAAE,CAChD,CAAC,MAAM,EAAE,EAAE,CACT,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAEnB,uBAAuB;AACvB,iFAAiF;AACjF,kFAAkF;AAClF,sEAAsE;AACtE,EAAE;AACF,6DAA6D;AAC7D,wCAAwC;AACxC,OAAO"}
@@ -0,0 +1,71 @@
1
+ /** Represents a State computation: a pure function (s: S) => readonly [A, S]. */
2
+ export type State<S, A> = {
3
+ readonly tag: 'State';
4
+ readonly run: (s: S) => readonly [A, S];
5
+ };
6
+ /**
7
+ * Construct a State from a function.
8
+ * @param run - The function that computes a value and new state.
9
+ * @returns A State that encapsulates the computation.
10
+ */
11
+ export declare const State: <S, A>(run: (s: S) => readonly [A, S]) => State<S, A>;
12
+ /**
13
+ * Retrieve the current state.
14
+ * @returns A State that returns the state as its value.
15
+ */
16
+ export declare const get: <S>() => State<S, S>;
17
+ /**
18
+ * Replace the state.
19
+ * @param s - The new state.
20
+ * @returns A State that replaces the current state and returns void.
21
+ */
22
+ export declare const put: <S>(s: S) => State<S, void>;
23
+ /**
24
+ * Transform the state.
25
+ * @param f - Function to transform the state.
26
+ * @returns A State that applies the transformation and returns void.
27
+ */
28
+ export declare const modify: <S>(f: (s: S) => S) => State<S, void>;
29
+ /**
30
+ * Retrieve and transform the state.
31
+ * @param f - Function to transform the state.
32
+ * @returns A State that applies the function to the state and returns the result.
33
+ */
34
+ export declare const gets: <S, A>(f: (s: S) => A) => State<S, A>;
35
+ /**
36
+ * Functor map over the value.
37
+ * @param f - Function to transform the value.
38
+ * @returns A function that takes a State and returns a new State with mapped value.
39
+ */
40
+ export declare const map: <A, B>(f: (a: A) => B) => (<S>(state: State<S, A>) => State<S, B>);
41
+ /**
42
+ * Applicative ap: apply a State function to a State value.
43
+ * @param sf - A State containing a function.
44
+ * @returns A function that takes a State and returns a new State with applied function.
45
+ */
46
+ export declare const ap: <S, A, B>(sf: State<S, (a: A) => B>) => ((sa: State<S, A>) => State<S, B>);
47
+ /**
48
+ * Monadic bind: sequentially compose two State computations.
49
+ * @param f - Function that returns a new State.
50
+ * @returns A function that takes a State and returns a new State.
51
+ */
52
+ export declare const chain: <S, A, B>(f: (a: A) => State<S, B>) => ((state: State<S, A>) => State<S, B>);
53
+ /**
54
+ * Execute a State computation with an initial state.
55
+ * @param state - The initial state.
56
+ * @returns A function that takes a State and returns the result pair.
57
+ */
58
+ export declare const runState: <S, A>(state: S) => ((computation: State<S, A>) => readonly [A, S]);
59
+ /**
60
+ * Execute a State computation and extract only the value.
61
+ * @param state - The initial state.
62
+ * @returns A function that takes a State and returns only the value.
63
+ */
64
+ export declare const evalState: <S, A>(state: S) => ((computation: State<S, A>) => A);
65
+ /**
66
+ * Execute a State computation and extract only the final state.
67
+ * @param state - The initial state.
68
+ * @returns A function that takes a State and returns only the final state.
69
+ */
70
+ export declare const execState: <S, A>(state: S) => ((computation: State<S, A>) => S);
71
+ //# sourceMappingURL=State.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"State.d.ts","sourceRoot":"","sources":["../../src/State.ts"],"names":[],"mappings":"AAE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