@lsby/ts-fp-data 0.1.0 → 0.1.3

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.
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/data/lazy.ts
21
+ var lazy_exports = {};
22
+ __export(lazy_exports, {
23
+ Lazy: () => Lazy,
24
+ LazyDeferValue: () => LazyDeferValue,
25
+ LazyForceValue: () => LazyForceValue
26
+ });
27
+ module.exports = __toCommonJS(lazy_exports);
28
+ var Lazy = class {
29
+ };
30
+ var LazyDeferValue = class _LazyDeferValue extends Lazy {
31
+ constructor(value) {
32
+ super();
33
+ this.value = value;
34
+ }
35
+ cache = null;
36
+ run() {
37
+ if (this.cache)
38
+ return this.cache;
39
+ this.cache = this.value();
40
+ return this.cache;
41
+ }
42
+ map(f) {
43
+ return new _LazyDeferValue(() => f(this.run()));
44
+ }
45
+ };
46
+ var LazyForceValue = class _LazyForceValue extends Lazy {
47
+ constructor(value) {
48
+ super();
49
+ this.value = value;
50
+ }
51
+ run() {
52
+ return this.value;
53
+ }
54
+ map(f) {
55
+ return new _LazyForceValue(f(this.run()));
56
+ }
57
+ };
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ Lazy,
61
+ LazyDeferValue,
62
+ LazyForceValue
63
+ });
@@ -0,0 +1,19 @@
1
+ declare abstract class Lazy<A> {
2
+ abstract run(): A;
3
+ abstract map<B>(f: (a: A) => B): Lazy<B>;
4
+ }
5
+ declare class LazyDeferValue<A> extends Lazy<A> {
6
+ private value;
7
+ private cache;
8
+ constructor(value: () => A);
9
+ run(): A;
10
+ map<B>(f: (a: A) => B): Lazy<B>;
11
+ }
12
+ declare class LazyForceValue<A> extends Lazy<A> {
13
+ private value;
14
+ constructor(value: A);
15
+ run(): A;
16
+ map<B>(f: (a: A) => B): Lazy<B>;
17
+ }
18
+
19
+ export { Lazy, LazyDeferValue, LazyForceValue };
@@ -22,6 +22,9 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  Either: () => Either,
24
24
  Just: () => Just,
25
+ Lazy: () => Lazy,
26
+ LazyDeferValue: () => LazyDeferValue,
27
+ LazyForceValue: () => LazyForceValue,
25
28
  Left: () => Left,
26
29
  Maybe: () => Maybe,
27
30
  Nothing: () => Nothing,
@@ -114,6 +117,104 @@ var Right = class _Right extends Either {
114
117
  }
115
118
  };
116
119
 
120
+ // src/data/lazy.ts
121
+ var Lazy = class {
122
+ };
123
+ var LazyDeferValue = class _LazyDeferValue extends Lazy {
124
+ constructor(value) {
125
+ super();
126
+ this.value = value;
127
+ }
128
+ cache = null;
129
+ run() {
130
+ if (this.cache)
131
+ return this.cache;
132
+ this.cache = this.value();
133
+ return this.cache;
134
+ }
135
+ map(f) {
136
+ return new _LazyDeferValue(() => f(this.run()));
137
+ }
138
+ };
139
+ var LazyForceValue = class _LazyForceValue extends Lazy {
140
+ constructor(value) {
141
+ super();
142
+ this.value = value;
143
+ }
144
+ run() {
145
+ return this.value;
146
+ }
147
+ map(f) {
148
+ return new _LazyForceValue(f(this.run()));
149
+ }
150
+ };
151
+
152
+ // src/data/maybe.ts
153
+ var Maybe = class {
154
+ static pure(a) {
155
+ return new Just(a);
156
+ }
157
+ };
158
+ var Just = class _Just extends Maybe {
159
+ constructor(\u503C) {
160
+ super();
161
+ this.\u503C = \u503C;
162
+ }
163
+ map(f) {
164
+ return new _Just(f(this.\u503C));
165
+ }
166
+ bind(f) {
167
+ return f(this.\u503C);
168
+ }
169
+ isJust() {
170
+ return true;
171
+ }
172
+ isNothing() {
173
+ return false;
174
+ }
175
+ assertJust() {
176
+ return this;
177
+ }
178
+ assertNothing() {
179
+ throw new Error("\u65AD\u8A00\u5931\u8D25");
180
+ }
181
+ getJust() {
182
+ return this.\u503C;
183
+ }
184
+ getJustOrNull() {
185
+ return this.\u503C;
186
+ }
187
+ match(onJust, _onNothing) {
188
+ return onJust(this.\u503C);
189
+ }
190
+ };
191
+ var Nothing = class _Nothing extends Maybe {
192
+ map(_f) {
193
+ return new _Nothing();
194
+ }
195
+ bind(_f) {
196
+ return new _Nothing();
197
+ }
198
+ isJust() {
199
+ return false;
200
+ }
201
+ isNothing() {
202
+ return true;
203
+ }
204
+ assertJust() {
205
+ throw new Error("\u65AD\u8A00\u5931\u8D25");
206
+ }
207
+ assertNothing() {
208
+ return this;
209
+ }
210
+ getJustOrNull() {
211
+ return null;
212
+ }
213
+ match(_onJust, onNothing) {
214
+ return onNothing();
215
+ }
216
+ };
217
+
117
218
  // src/data/task.ts
118
219
  var TaskDo = class _TaskDo {
119
220
  constructor(accTask) {
@@ -208,72 +309,6 @@ var Task = class _Task {
208
309
  }
209
310
  };
210
311
 
211
- // src/data/maybe.ts
212
- var Maybe = class {
213
- static pure(a) {
214
- return new Just(a);
215
- }
216
- };
217
- var Just = class _Just extends Maybe {
218
- constructor(\u503C) {
219
- super();
220
- this.\u503C = \u503C;
221
- }
222
- map(f) {
223
- return new _Just(f(this.\u503C));
224
- }
225
- bind(f) {
226
- return f(this.\u503C);
227
- }
228
- isJust() {
229
- return true;
230
- }
231
- isNothing() {
232
- return false;
233
- }
234
- assertJust() {
235
- return this;
236
- }
237
- assertNothing() {
238
- throw new Error("\u65AD\u8A00\u5931\u8D25");
239
- }
240
- getJust() {
241
- return this.\u503C;
242
- }
243
- getJustOrNull() {
244
- return this.\u503C;
245
- }
246
- match(onJust, _onNothing) {
247
- return onJust(this.\u503C);
248
- }
249
- };
250
- var Nothing = class _Nothing extends Maybe {
251
- map(_f) {
252
- return new _Nothing();
253
- }
254
- bind(_f) {
255
- return new _Nothing();
256
- }
257
- isJust() {
258
- return false;
259
- }
260
- isNothing() {
261
- return true;
262
- }
263
- assertJust() {
264
- throw new Error("\u65AD\u8A00\u5931\u8D25");
265
- }
266
- assertNothing() {
267
- return this;
268
- }
269
- getJustOrNull() {
270
- return null;
271
- }
272
- match(_onJust, onNothing) {
273
- return onNothing();
274
- }
275
- };
276
-
277
312
  // src/func/seq.ts
278
313
  function seqArrayTask(a) {
279
314
  return new Task(async () => {
@@ -303,6 +338,9 @@ function seqArrayEither(value) {
303
338
  0 && (module.exports = {
304
339
  Either,
305
340
  Just,
341
+ Lazy,
342
+ LazyDeferValue,
343
+ LazyForceValue,
306
344
  Left,
307
345
  Maybe,
308
346
  Nothing,
@@ -1,4 +1,5 @@
1
- export { Task, TaskDo, TaskDoType, TaskDoTypeBase, TaskDoTypeGet, TaskDoTypeIf, TaskDoTypeIfReturn, TaskDoTypeNoGet, TaskDoTypeReturn } from './data/task.cjs';
2
- export { Just, Maybe, Nothing } from './data/maybe.cjs';
3
1
  export { Either, Left, Right } from './data/either.cjs';
2
+ export { Lazy, LazyDeferValue, LazyForceValue } from './data/lazy.cjs';
3
+ export { Just, Maybe, Nothing } from './data/maybe.cjs';
4
+ export { Task, TaskDo, TaskDoType, TaskDoTypeBase, TaskDoTypeGet, TaskDoTypeIf, TaskDoTypeIfReturn, TaskDoTypeNoGet, TaskDoTypeReturn } from './data/task.cjs';
4
5
  export { seqArrayEither, seqArrayTask, seqEitherArray, seqEitherTask } from './func/seq.cjs';
@@ -0,0 +1,37 @@
1
+ // src/data/lazy.ts
2
+ var Lazy = class {
3
+ };
4
+ var LazyDeferValue = class _LazyDeferValue extends Lazy {
5
+ constructor(value) {
6
+ super();
7
+ this.value = value;
8
+ }
9
+ cache = null;
10
+ run() {
11
+ if (this.cache)
12
+ return this.cache;
13
+ this.cache = this.value();
14
+ return this.cache;
15
+ }
16
+ map(f) {
17
+ return new _LazyDeferValue(() => f(this.run()));
18
+ }
19
+ };
20
+ var LazyForceValue = class _LazyForceValue extends Lazy {
21
+ constructor(value) {
22
+ super();
23
+ this.value = value;
24
+ }
25
+ run() {
26
+ return this.value;
27
+ }
28
+ map(f) {
29
+ return new _LazyForceValue(f(this.run()));
30
+ }
31
+ };
32
+
33
+ export {
34
+ Lazy,
35
+ LazyDeferValue,
36
+ LazyForceValue
37
+ };
@@ -0,0 +1,19 @@
1
+ declare abstract class Lazy<A> {
2
+ abstract run(): A;
3
+ abstract map<B>(f: (a: A) => B): Lazy<B>;
4
+ }
5
+ declare class LazyDeferValue<A> extends Lazy<A> {
6
+ private value;
7
+ private cache;
8
+ constructor(value: () => A);
9
+ run(): A;
10
+ map<B>(f: (a: A) => B): Lazy<B>;
11
+ }
12
+ declare class LazyForceValue<A> extends Lazy<A> {
13
+ private value;
14
+ constructor(value: A);
15
+ run(): A;
16
+ map<B>(f: (a: A) => B): Lazy<B>;
17
+ }
18
+
19
+ export { Lazy, LazyDeferValue, LazyForceValue };
@@ -0,0 +1,10 @@
1
+ import {
2
+ Lazy,
3
+ LazyDeferValue,
4
+ LazyForceValue
5
+ } from "../chunk-NEBLA4MD.js";
6
+ export {
7
+ Lazy,
8
+ LazyDeferValue,
9
+ LazyForceValue
10
+ };
@@ -1,4 +1,5 @@
1
- export { Task, TaskDo, TaskDoType, TaskDoTypeBase, TaskDoTypeGet, TaskDoTypeIf, TaskDoTypeIfReturn, TaskDoTypeNoGet, TaskDoTypeReturn } from './data/task.js';
2
- export { Just, Maybe, Nothing } from './data/maybe.js';
3
1
  export { Either, Left, Right } from './data/either.js';
2
+ export { Lazy, LazyDeferValue, LazyForceValue } from './data/lazy.js';
3
+ export { Just, Maybe, Nothing } from './data/maybe.js';
4
+ export { Task, TaskDo, TaskDoType, TaskDoTypeBase, TaskDoTypeGet, TaskDoTypeIf, TaskDoTypeIfReturn, TaskDoTypeNoGet, TaskDoTypeReturn } from './data/task.js';
4
5
  export { seqArrayEither, seqArrayTask, seqEitherArray, seqEitherTask } from './func/seq.js';
package/dist/esm/index.js CHANGED
@@ -1,3 +1,8 @@
1
+ import {
2
+ Lazy,
3
+ LazyDeferValue,
4
+ LazyForceValue
5
+ } from "./chunk-NEBLA4MD.js";
1
6
  import {
2
7
  Just,
3
8
  Maybe,
@@ -21,6 +26,9 @@ import {
21
26
  export {
22
27
  Either,
23
28
  Just,
29
+ Lazy,
30
+ LazyDeferValue,
31
+ LazyForceValue,
24
32
  Left,
25
33
  Maybe,
26
34
  Nothing,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsby/ts-fp-data",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "require": "./dist/cjs/index.cjs",