@lsby/ts-fp-data 0.0.6 → 0.0.8

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.
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/data/task.ts
21
21
  var task_exports = {};
22
22
  __export(task_exports, {
23
- Task: () => Task
23
+ Task: () => Task,
24
+ TaskDo: () => TaskDo
24
25
  });
25
26
  module.exports = __toCommonJS(task_exports);
26
27
 
@@ -104,6 +105,32 @@ var Right = class _Right extends Either {
104
105
  };
105
106
 
106
107
  // src/data/task.ts
108
+ var TaskDo = class _TaskDo {
109
+ constructor(accTask) {
110
+ this.accTask = accTask;
111
+ }
112
+ bind(name, task) {
113
+ return new _TaskDo(
114
+ this.accTask.bind((a) => task(a.env).bind((v) => Task.pure({ env: { ...a.env, [name]: v }, lastValue: v })))
115
+ );
116
+ }
117
+ exec(task) {
118
+ return new _TaskDo(this.accTask.bind((a) => task(a.env).bind((v) => Task.pure({ env: a.env, lastValue: v }))));
119
+ }
120
+ effect(task) {
121
+ return new _TaskDo(
122
+ this.accTask.bind((a) => Task.pure(task(a.env)).bind((v) => Task.pure({ env: a.env, lastValue: v })))
123
+ );
124
+ }
125
+ pure(value) {
126
+ return new _TaskDo(this.accTask.bind((a) => Task.pure(value).bind((v) => Task.pure({ env: a.env, lastValue: v }))));
127
+ }
128
+ getTask() {
129
+ return new Task(async () => {
130
+ return (await this.accTask.run()).lastValue;
131
+ });
132
+ }
133
+ };
107
134
  var Task = class _Task {
108
135
  constructor(f) {
109
136
  this.f = f;
@@ -111,6 +138,9 @@ var Task = class _Task {
111
138
  static pure(a) {
112
139
  return new _Task(async () => a);
113
140
  }
141
+ static do() {
142
+ return new TaskDo(new _Task(async () => ({ env: {}, lastValue: void 0 })));
143
+ }
114
144
  map(f) {
115
145
  return new _Task(async () => f(await this.f()));
116
146
  }
@@ -132,5 +162,6 @@ var Task = class _Task {
132
162
  };
133
163
  // Annotate the CommonJS export names for ESM import in node:
134
164
  0 && (module.exports = {
135
- Task
165
+ Task,
166
+ TaskDo
136
167
  });
@@ -1,8 +1,28 @@
1
1
  import { Either } from './either.cjs';
2
2
 
3
+ interface TaskDoType<Env extends Record<string, any>, A> {
4
+ bind<K extends string, X>(name: K, task: (env: Env) => Task<X>): TaskDoType<Env & Record<K, X>, X>;
5
+ exec<X>(task: (env: Env) => Task<X>): TaskDoType<Env, X>;
6
+ effect<X>(task: (env: Env) => X): TaskDoType<Env, X>;
7
+ pure<X>(value: X): TaskDoType<Env, X>;
8
+ getTask(): Task<A>;
9
+ }
10
+ declare class TaskDo<Env extends Record<string, any>, A> implements TaskDoType<Env, A> {
11
+ private accTask;
12
+ constructor(accTask: Task<{
13
+ env: Env;
14
+ lastValue: A;
15
+ }>);
16
+ bind<K extends string, X>(name: K, task: (env: Env) => Task<X>): TaskDoType<Env & Record<K, X>, X>;
17
+ exec<X>(task: (env: Env) => Task<X>): TaskDoType<Env, X>;
18
+ effect<X>(task: (env: Env) => X): TaskDoType<Env, X>;
19
+ pure<X>(value: X): TaskDoType<Env, X>;
20
+ getTask(): Task<A>;
21
+ }
3
22
  declare class Task<A> {
4
23
  private f;
5
24
  static pure<A>(a: A): Task<A>;
25
+ static do(): TaskDo<Record<string, any>, void>;
6
26
  constructor(f: () => Promise<A>);
7
27
  map<B>(f: (a: A) => B): Task<B>;
8
28
  bind<B>(f: (a: A) => Task<B>): Task<B>;
@@ -10,4 +30,4 @@ declare class Task<A> {
10
30
  tryRun(): Promise<Either<Error, A>>;
11
31
  }
12
32
 
13
- export { Task };
33
+ export { Task, TaskDo, type TaskDoType };
@@ -107,6 +107,32 @@ var Right = class _Right extends Either {
107
107
  };
108
108
 
109
109
  // src/data/task.ts
110
+ var TaskDo = class _TaskDo {
111
+ constructor(accTask) {
112
+ this.accTask = accTask;
113
+ }
114
+ bind(name, task) {
115
+ return new _TaskDo(
116
+ this.accTask.bind((a) => task(a.env).bind((v) => Task.pure({ env: { ...a.env, [name]: v }, lastValue: v })))
117
+ );
118
+ }
119
+ exec(task) {
120
+ return new _TaskDo(this.accTask.bind((a) => task(a.env).bind((v) => Task.pure({ env: a.env, lastValue: v }))));
121
+ }
122
+ effect(task) {
123
+ return new _TaskDo(
124
+ this.accTask.bind((a) => Task.pure(task(a.env)).bind((v) => Task.pure({ env: a.env, lastValue: v })))
125
+ );
126
+ }
127
+ pure(value) {
128
+ return new _TaskDo(this.accTask.bind((a) => Task.pure(value).bind((v) => Task.pure({ env: a.env, lastValue: v }))));
129
+ }
130
+ getTask() {
131
+ return new Task(async () => {
132
+ return (await this.accTask.run()).lastValue;
133
+ });
134
+ }
135
+ };
110
136
  var Task = class _Task {
111
137
  constructor(f) {
112
138
  this.f = f;
@@ -114,6 +140,9 @@ var Task = class _Task {
114
140
  static pure(a) {
115
141
  return new _Task(async () => a);
116
142
  }
143
+ static do() {
144
+ return new TaskDo(new _Task(async () => ({ env: {}, lastValue: void 0 })));
145
+ }
117
146
  map(f) {
118
147
  return new _Task(async () => f(await this.f()));
119
148
  }
@@ -27,6 +27,7 @@ __export(src_exports, {
27
27
  Nothing: () => Nothing,
28
28
  Right: () => Right,
29
29
  Task: () => Task,
30
+ TaskDo: () => TaskDo,
30
31
  seqArrayEither: () => seqArrayEither,
31
32
  seqArrayTask: () => seqArrayTask,
32
33
  seqEitherArray: () => seqEitherArray,
@@ -114,6 +115,32 @@ var Right = class _Right extends Either {
114
115
  };
115
116
 
116
117
  // src/data/task.ts
118
+ var TaskDo = class _TaskDo {
119
+ constructor(accTask) {
120
+ this.accTask = accTask;
121
+ }
122
+ bind(name, task) {
123
+ return new _TaskDo(
124
+ this.accTask.bind((a) => task(a.env).bind((v) => Task.pure({ env: { ...a.env, [name]: v }, lastValue: v })))
125
+ );
126
+ }
127
+ exec(task) {
128
+ return new _TaskDo(this.accTask.bind((a) => task(a.env).bind((v) => Task.pure({ env: a.env, lastValue: v }))));
129
+ }
130
+ effect(task) {
131
+ return new _TaskDo(
132
+ this.accTask.bind((a) => Task.pure(task(a.env)).bind((v) => Task.pure({ env: a.env, lastValue: v })))
133
+ );
134
+ }
135
+ pure(value) {
136
+ return new _TaskDo(this.accTask.bind((a) => Task.pure(value).bind((v) => Task.pure({ env: a.env, lastValue: v }))));
137
+ }
138
+ getTask() {
139
+ return new Task(async () => {
140
+ return (await this.accTask.run()).lastValue;
141
+ });
142
+ }
143
+ };
117
144
  var Task = class _Task {
118
145
  constructor(f) {
119
146
  this.f = f;
@@ -121,6 +148,9 @@ var Task = class _Task {
121
148
  static pure(a) {
122
149
  return new _Task(async () => a);
123
150
  }
151
+ static do() {
152
+ return new TaskDo(new _Task(async () => ({ env: {}, lastValue: void 0 })));
153
+ }
124
154
  map(f) {
125
155
  return new _Task(async () => f(await this.f()));
126
156
  }
@@ -229,6 +259,7 @@ function seqArrayEither(value) {
229
259
  Nothing,
230
260
  Right,
231
261
  Task,
262
+ TaskDo,
232
263
  seqArrayEither,
233
264
  seqArrayTask,
234
265
  seqEitherArray,
@@ -1,4 +1,4 @@
1
- export { Task } from './data/task.cjs';
1
+ export { Task, TaskDo, TaskDoType } from './data/task.cjs';
2
2
  export { Just, Maybe, Nothing } from './data/maybe.cjs';
3
3
  export { Either, Left, Right } from './data/either.cjs';
4
4
  export { seqArrayEither, seqArrayTask, seqEitherArray, seqEitherTask } from './func/seq.cjs';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Task
3
- } from "./chunk-2AQUF5MK.js";
3
+ } from "./chunk-XP6AXTYL.js";
4
4
  import {
5
5
  Left,
6
6
  Right
@@ -0,0 +1,66 @@
1
+ import {
2
+ Left,
3
+ Right
4
+ } from "./chunk-VTI5CRVQ.js";
5
+
6
+ // src/data/task.ts
7
+ var TaskDo = class _TaskDo {
8
+ constructor(accTask) {
9
+ this.accTask = accTask;
10
+ }
11
+ bind(name, task) {
12
+ return new _TaskDo(
13
+ this.accTask.bind((a) => task(a.env).bind((v) => Task.pure({ env: { ...a.env, [name]: v }, lastValue: v })))
14
+ );
15
+ }
16
+ exec(task) {
17
+ return new _TaskDo(this.accTask.bind((a) => task(a.env).bind((v) => Task.pure({ env: a.env, lastValue: v }))));
18
+ }
19
+ effect(task) {
20
+ return new _TaskDo(
21
+ this.accTask.bind((a) => Task.pure(task(a.env)).bind((v) => Task.pure({ env: a.env, lastValue: v })))
22
+ );
23
+ }
24
+ pure(value) {
25
+ return new _TaskDo(this.accTask.bind((a) => Task.pure(value).bind((v) => Task.pure({ env: a.env, lastValue: v }))));
26
+ }
27
+ getTask() {
28
+ return new Task(async () => {
29
+ return (await this.accTask.run()).lastValue;
30
+ });
31
+ }
32
+ };
33
+ var Task = class _Task {
34
+ constructor(f) {
35
+ this.f = f;
36
+ }
37
+ static pure(a) {
38
+ return new _Task(async () => a);
39
+ }
40
+ static do() {
41
+ return new TaskDo(new _Task(async () => ({ env: {}, lastValue: void 0 })));
42
+ }
43
+ map(f) {
44
+ return new _Task(async () => f(await this.f()));
45
+ }
46
+ bind(f) {
47
+ return new _Task(async () => f(await this.f()).run());
48
+ }
49
+ run() {
50
+ return this.f();
51
+ }
52
+ async tryRun() {
53
+ try {
54
+ return new Right(await this.run());
55
+ } catch (e) {
56
+ if (e instanceof Error)
57
+ return new Left(e);
58
+ return new Left(new Error(String(e)));
59
+ }
60
+ }
61
+ };
62
+
63
+ export {
64
+ TaskDo,
65
+ Task
66
+ };
@@ -1,8 +1,28 @@
1
1
  import { Either } from './either.js';
2
2
 
3
+ interface TaskDoType<Env extends Record<string, any>, A> {
4
+ bind<K extends string, X>(name: K, task: (env: Env) => Task<X>): TaskDoType<Env & Record<K, X>, X>;
5
+ exec<X>(task: (env: Env) => Task<X>): TaskDoType<Env, X>;
6
+ effect<X>(task: (env: Env) => X): TaskDoType<Env, X>;
7
+ pure<X>(value: X): TaskDoType<Env, X>;
8
+ getTask(): Task<A>;
9
+ }
10
+ declare class TaskDo<Env extends Record<string, any>, A> implements TaskDoType<Env, A> {
11
+ private accTask;
12
+ constructor(accTask: Task<{
13
+ env: Env;
14
+ lastValue: A;
15
+ }>);
16
+ bind<K extends string, X>(name: K, task: (env: Env) => Task<X>): TaskDoType<Env & Record<K, X>, X>;
17
+ exec<X>(task: (env: Env) => Task<X>): TaskDoType<Env, X>;
18
+ effect<X>(task: (env: Env) => X): TaskDoType<Env, X>;
19
+ pure<X>(value: X): TaskDoType<Env, X>;
20
+ getTask(): Task<A>;
21
+ }
3
22
  declare class Task<A> {
4
23
  private f;
5
24
  static pure<A>(a: A): Task<A>;
25
+ static do(): TaskDo<Record<string, any>, void>;
6
26
  constructor(f: () => Promise<A>);
7
27
  map<B>(f: (a: A) => B): Task<B>;
8
28
  bind<B>(f: (a: A) => Task<B>): Task<B>;
@@ -10,4 +30,4 @@ declare class Task<A> {
10
30
  tryRun(): Promise<Either<Error, A>>;
11
31
  }
12
32
 
13
- export { Task };
33
+ export { Task, TaskDo, type TaskDoType };
@@ -1,7 +1,9 @@
1
1
  import {
2
- Task
3
- } from "../chunk-2AQUF5MK.js";
2
+ Task,
3
+ TaskDo
4
+ } from "../chunk-XP6AXTYL.js";
4
5
  import "../chunk-VTI5CRVQ.js";
5
6
  export {
6
- Task
7
+ Task,
8
+ TaskDo
7
9
  };
@@ -3,8 +3,8 @@ import {
3
3
  seqArrayTask,
4
4
  seqEitherArray,
5
5
  seqEitherTask
6
- } from "../chunk-M4F5SG35.js";
7
- import "../chunk-2AQUF5MK.js";
6
+ } from "../chunk-3DBX3JLQ.js";
7
+ import "../chunk-XP6AXTYL.js";
8
8
  import "../chunk-VTI5CRVQ.js";
9
9
  export {
10
10
  seqArrayEither,
@@ -1,4 +1,4 @@
1
- export { Task } from './data/task.js';
1
+ export { Task, TaskDo, TaskDoType } from './data/task.js';
2
2
  export { Just, Maybe, Nothing } from './data/maybe.js';
3
3
  export { Either, Left, Right } from './data/either.js';
4
4
  export { seqArrayEither, seqArrayTask, seqEitherArray, seqEitherTask } from './func/seq.js';
package/dist/esm/index.js CHANGED
@@ -8,10 +8,11 @@ import {
8
8
  seqArrayTask,
9
9
  seqEitherArray,
10
10
  seqEitherTask
11
- } from "./chunk-M4F5SG35.js";
11
+ } from "./chunk-3DBX3JLQ.js";
12
12
  import {
13
- Task
14
- } from "./chunk-2AQUF5MK.js";
13
+ Task,
14
+ TaskDo
15
+ } from "./chunk-XP6AXTYL.js";
15
16
  import {
16
17
  Either,
17
18
  Left,
@@ -25,6 +26,7 @@ export {
25
26
  Nothing,
26
27
  Right,
27
28
  Task,
29
+ TaskDo,
28
30
  seqArrayEither,
29
31
  seqArrayTask,
30
32
  seqEitherArray,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lsby/ts-fp-data",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "require": "./dist/cjs/index.cjs",
@@ -36,6 +36,7 @@
36
36
  "other:pub": "npm run other:typecheck && npm run build:all && bumpp && pnpm -r publish --access public",
37
37
  "other:typecheck": "tsc --noEmit",
38
38
  "other:typecheck:watch": "tsc --noEmit -w",
39
- "run:start": "tsx src/index.ts"
39
+ "run:start": "tsx src/index.ts",
40
+ "run:test": "tsx test/index.ts"
40
41
  }
41
42
  }
@@ -1,36 +0,0 @@
1
- import {
2
- Left,
3
- Right
4
- } from "./chunk-VTI5CRVQ.js";
5
-
6
- // src/data/task.ts
7
- var Task = class _Task {
8
- constructor(f) {
9
- this.f = f;
10
- }
11
- static pure(a) {
12
- return new _Task(async () => a);
13
- }
14
- map(f) {
15
- return new _Task(async () => f(await this.f()));
16
- }
17
- bind(f) {
18
- return new _Task(async () => f(await this.f()).run());
19
- }
20
- run() {
21
- return this.f();
22
- }
23
- async tryRun() {
24
- try {
25
- return new Right(await this.run());
26
- } catch (e) {
27
- if (e instanceof Error)
28
- return new Left(e);
29
- return new Left(new Error(String(e)));
30
- }
31
- }
32
- };
33
-
34
- export {
35
- Task
36
- };