functype 0.0.1

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 (55) hide show
  1. package/README.md +3 -0
  2. package/dist/Left-7cd8288c.d.ts +28 -0
  3. package/dist/Left-876f22af.d.ts +28 -0
  4. package/dist/chunk-6VKVA3TK.cjs +1 -0
  5. package/dist/chunk-FA5LZ3YI.cjs +1 -0
  6. package/dist/chunk-GWLTG6GZ.cjs +1 -0
  7. package/dist/chunk-IDDQN36F.js +1 -0
  8. package/dist/chunk-TH2FAVW2.cjs +1 -0
  9. package/dist/chunk-VTKL7OQI.js +1 -0
  10. package/dist/chunk-ZPTW4ENU.js +1 -0
  11. package/dist/chunk-ZTL76QDL.js +1 -0
  12. package/dist/either/Left.cjs +1 -0
  13. package/dist/either/Left.d.cts +2 -0
  14. package/dist/either/Left.d.ts +2 -0
  15. package/dist/either/Left.js +1 -0
  16. package/dist/either/Right.cjs +1 -0
  17. package/dist/either/Right.d.cts +2 -0
  18. package/dist/either/Right.d.ts +2 -0
  19. package/dist/either/Right.js +1 -0
  20. package/dist/either/index.cjs +1 -0
  21. package/dist/either/index.d.cts +2 -0
  22. package/dist/either/index.d.ts +2 -0
  23. package/dist/either/index.js +1 -0
  24. package/dist/error/ParseError.cjs +1 -0
  25. package/dist/error/ParseError.d.cts +4 -0
  26. package/dist/error/ParseError.d.ts +4 -0
  27. package/dist/error/ParseError.js +1 -0
  28. package/dist/index.cjs +1 -0
  29. package/dist/index.d.cts +2 -0
  30. package/dist/index.d.ts +2 -0
  31. package/dist/index.js +0 -0
  32. package/dist/list/List.cjs +1 -0
  33. package/dist/list/List.d.cts +11 -0
  34. package/dist/list/List.d.ts +11 -0
  35. package/dist/list/List.js +1 -0
  36. package/lib/Left-916151dc.d.ts +23 -0
  37. package/lib/chunk-GAPG2VLO.cjs +10 -0
  38. package/lib/chunk-KMAXXKJT.js +10 -0
  39. package/lib/either/Left.cjs +26 -0
  40. package/lib/either/Left.d.cts +1 -0
  41. package/lib/either/Left.d.ts +1 -0
  42. package/lib/either/Left.js +26 -0
  43. package/lib/either/Right.cjs +24 -0
  44. package/lib/either/Right.d.cts +1 -0
  45. package/lib/either/Right.d.ts +1 -0
  46. package/lib/either/Right.js +24 -0
  47. package/lib/either/index.cjs +11 -0
  48. package/lib/either/index.d.cts +1 -0
  49. package/lib/either/index.d.ts +1 -0
  50. package/lib/either/index.js +11 -0
  51. package/lib/index.cjs +1 -0
  52. package/lib/index.d.cts +2 -0
  53. package/lib/index.d.ts +1 -0
  54. package/lib/index.js +0 -0
  55. package/package.json +48 -0
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ ## functype
2
+
3
+ A small functional library for TypeScript
@@ -0,0 +1,28 @@
1
+ import { ParseError } from './error/ParseError.cjs';
2
+
3
+ declare class Right<L, R> {
4
+ value: R;
5
+ readonly tag = "Right";
6
+ constructor(value: R);
7
+ isLeft(): this is Left<L, R>;
8
+ isRight(): this is Right<L, R>;
9
+ map<U>(f: (value: R) => U): Either<L, U>;
10
+ flatMap<U>(f: (value: R) => Either<L, U>): Either<L, U>;
11
+ }
12
+
13
+ type Either<L, R> = Left<L, R> | Right<L, R>;
14
+ declare const left: <L, R>(value: L) => Either<L, R>;
15
+ declare const right: <L, R>(value: R) => Either<L, R>;
16
+ declare const parseNumber: (input: string) => Either<ParseError, number>;
17
+
18
+ declare class Left<L, R> {
19
+ value: L;
20
+ readonly tag = "Left";
21
+ constructor(value: L);
22
+ isLeft(): this is Left<L, R>;
23
+ isRight(): this is Right<L, R>;
24
+ map<U>(f: (value: R) => U): Either<L, U>;
25
+ flatMap<U>(f: (value: R) => Either<L, U>): Either<L, U>;
26
+ }
27
+
28
+ export { Either as E, Left as L, Right as R, left as l, parseNumber as p, right as r };
@@ -0,0 +1,28 @@
1
+ import { ParseError } from './error/ParseError.js';
2
+
3
+ declare class Right<L, R> {
4
+ value: R;
5
+ readonly tag = "Right";
6
+ constructor(value: R);
7
+ isLeft(): this is Left<L, R>;
8
+ isRight(): this is Right<L, R>;
9
+ map<U>(f: (value: R) => U): Either<L, U>;
10
+ flatMap<U>(f: (value: R) => Either<L, U>): Either<L, U>;
11
+ }
12
+
13
+ type Either<L, R> = Left<L, R> | Right<L, R>;
14
+ declare const left: <L, R>(value: L) => Either<L, R>;
15
+ declare const right: <L, R>(value: R) => Either<L, R>;
16
+ declare const parseNumber: (input: string) => Either<ParseError, number>;
17
+
18
+ declare class Left<L, R> {
19
+ value: L;
20
+ readonly tag = "Left";
21
+ constructor(value: L);
22
+ isLeft(): this is Left<L, R>;
23
+ isRight(): this is Right<L, R>;
24
+ map<U>(f: (value: R) => U): Either<L, U>;
25
+ flatMap<U>(f: (value: R) => Either<L, U>): Either<L, U>;
26
+ }
27
+
28
+ export { Either as E, Left as L, Right as R, left as l, parseNumber as p, right as r };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var e=class extends Error{};exports.a = e;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkGWLTG6GZcjs = require('./chunk-GWLTG6GZ.cjs');var r=class i{constructor(t){this.value=t;_chunkGWLTG6GZcjs.a.call(void 0, this,"tag","Right")}isLeft(){return!1}isRight(){return!0}map(t){return new i(t(this.value))}flatMap(t){return t(this.value)}};exports.a = r;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var d=Object.defineProperty;var e=(b,a,c)=>a in b?d(b,a,{enumerable:!0,configurable:!0,writable:!0,value:c}):b[a]=c;var f=(b,a,c)=>(e(b,typeof a!="symbol"?a+"":a,c),c);exports.a = f;
@@ -0,0 +1 @@
1
+ import{a as e}from"./chunk-VTKL7OQI.js";var r=class i{constructor(t){this.value=t;e(this,"tag","Right")}isLeft(){return!1}isRight(){return!0}map(t){return new i(t(this.value))}flatMap(t){return t(this.value)}};export{r as a};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkGWLTG6GZcjs = require('./chunk-GWLTG6GZ.cjs');var i=class t{constructor(e){this.value=e;_chunkGWLTG6GZcjs.a.call(void 0, this,"tag","Left")}isLeft(){return!0}isRight(){return!1}map(e){return new t(this.value)}flatMap(e){return new t(this.value)}};exports.a = i;
@@ -0,0 +1 @@
1
+ var d=Object.defineProperty;var e=(b,a,c)=>a in b?d(b,a,{enumerable:!0,configurable:!0,writable:!0,value:c}):b[a]=c;var f=(b,a,c)=>(e(b,typeof a!="symbol"?a+"":a,c),c);export{f as a};
@@ -0,0 +1 @@
1
+ import{a as r}from"./chunk-VTKL7OQI.js";var i=class t{constructor(e){this.value=e;r(this,"tag","Left")}isLeft(){return!0}isRight(){return!1}map(e){return new t(this.value)}flatMap(e){return new t(this.value)}};export{i as a};
@@ -0,0 +1 @@
1
+ var e=class extends Error{};export{e as a};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkTH2FAVW2cjs = require('../chunk-TH2FAVW2.cjs');require('../chunk-GWLTG6GZ.cjs');exports.Left = _chunkTH2FAVW2cjs.a;
@@ -0,0 +1,2 @@
1
+ export { L as Left } from '../Left-7cd8288c.js';
2
+ import '../error/ParseError.cjs';
@@ -0,0 +1,2 @@
1
+ export { L as Left } from '../Left-876f22af.js';
2
+ import '../error/ParseError.js';
@@ -0,0 +1 @@
1
+ import{a}from"../chunk-ZPTW4ENU.js";import"../chunk-VTKL7OQI.js";export{a as Left};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkFA5LZ3YIcjs = require('../chunk-FA5LZ3YI.cjs');require('../chunk-GWLTG6GZ.cjs');exports.Right = _chunkFA5LZ3YIcjs.a;
@@ -0,0 +1,2 @@
1
+ export { R as Right } from '../Left-7cd8288c.js';
2
+ import '../error/ParseError.cjs';
@@ -0,0 +1,2 @@
1
+ export { R as Right } from '../Left-876f22af.js';
2
+ import '../error/ParseError.js';
@@ -0,0 +1 @@
1
+ import{a}from"../chunk-IDDQN36F.js";import"../chunk-VTKL7OQI.js";export{a as Right};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkTH2FAVW2cjs = require('../chunk-TH2FAVW2.cjs');var _chunkFA5LZ3YIcjs = require('../chunk-FA5LZ3YI.cjs');var _chunk6VKVA3TKcjs = require('../chunk-6VKVA3TK.cjs');require('../chunk-GWLTG6GZ.cjs');var n=r=>new (0, _chunkTH2FAVW2cjs.a)(r),s= exports.right =r=>new (0, _chunkFA5LZ3YIcjs.a)(r),m= exports.parseNumber =r=>{let t=parseInt(r,10);return isNaN(t)?n(new (0, _chunk6VKVA3TKcjs.a)(`${t}`)):s(t)};exports.left = n; exports.parseNumber = m; exports.right = s;
@@ -0,0 +1,2 @@
1
+ import '../error/ParseError.cjs';
2
+ export { E as Either, l as left, p as parseNumber, r as right } from '../Left-7cd8288c.js';
@@ -0,0 +1,2 @@
1
+ import '../error/ParseError.js';
2
+ export { E as Either, l as left, p as parseNumber, r as right } from '../Left-876f22af.js';
@@ -0,0 +1 @@
1
+ import{a as e}from"../chunk-ZPTW4ENU.js";import{a as o}from"../chunk-IDDQN36F.js";import{a as i}from"../chunk-ZTL76QDL.js";import"../chunk-VTKL7OQI.js";var n=r=>new e(r),s=r=>new o(r),m=r=>{let t=parseInt(r,10);return isNaN(t)?n(new i(`${t}`)):s(t)};export{n as left,m as parseNumber,s as right};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk6VKVA3TKcjs = require('../chunk-6VKVA3TK.cjs');require('../chunk-GWLTG6GZ.cjs');exports.ParseError = _chunk6VKVA3TKcjs.a;
@@ -0,0 +1,4 @@
1
+ declare class ParseError extends Error {
2
+ }
3
+
4
+ export { ParseError };
@@ -0,0 +1,4 @@
1
+ declare class ParseError extends Error {
2
+ }
3
+
4
+ export { ParseError };
@@ -0,0 +1 @@
1
+ import{a}from"../chunk-ZTL76QDL.js";import"../chunk-VTKL7OQI.js";export{a as ParseError};
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/index.js ADDED
File without changes
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkGWLTG6GZcjs = require('../chunk-GWLTG6GZ.cjs');var r=class e{constructor(t){_chunkGWLTG6GZcjs.a.call(void 0, this,"items");this.items=t?[...t]:[]}get length(){return this.items.length}add(t){return new e([...this.items,t])}removeAt(t){if(t<0||t>=this.items.length)return this;let i=[...this.items.slice(0,t),...this.items.slice(t+1)];return new e(i)}get(t){return this.items[t]}toArray(){return this.items}};exports.List = r;
@@ -0,0 +1,11 @@
1
+ declare class List<T> {
2
+ private readonly items;
3
+ constructor(items?: T[]);
4
+ get length(): number;
5
+ add(item: T): List<T>;
6
+ removeAt(index: number): List<T>;
7
+ get(index: number): T | undefined;
8
+ toArray(): readonly T[];
9
+ }
10
+
11
+ export { List };
@@ -0,0 +1,11 @@
1
+ declare class List<T> {
2
+ private readonly items;
3
+ constructor(items?: T[]);
4
+ get length(): number;
5
+ add(item: T): List<T>;
6
+ removeAt(index: number): List<T>;
7
+ get(index: number): T | undefined;
8
+ toArray(): readonly T[];
9
+ }
10
+
11
+ export { List };
@@ -0,0 +1 @@
1
+ import{a as s}from"../chunk-VTKL7OQI.js";var r=class e{constructor(t){s(this,"items");this.items=t?[...t]:[]}get length(){return this.items.length}add(t){return new e([...this.items,t])}removeAt(t){if(t<0||t>=this.items.length)return this;let i=[...this.items.slice(0,t),...this.items.slice(t+1)];return new e(i)}get(t){return this.items[t]}toArray(){return this.items}};export{r as List};
@@ -0,0 +1,23 @@
1
+ type Either<L, R> = Left<L, R> | Right<L, R>
2
+
3
+ declare class Right<L, R> {
4
+ value: R
5
+ readonly tag = "Right"
6
+ constructor(value: R)
7
+ isLeft(): this is Left<L, R>
8
+ isRight(): this is Right<L, R>
9
+ map<U>(f: (value: R) => U): Either<L, U>
10
+ flatMap<U>(f: (value: R) => Either<L, U>): Either<L, U>
11
+ }
12
+
13
+ declare class Left<L, R> {
14
+ value: L
15
+ readonly tag = "Left"
16
+ constructor(value: L)
17
+ isLeft(): this is Left<L, R>
18
+ isRight(): this is Right<L, R>
19
+ map<U>(f: (value: R) => U): Either<L, U>
20
+ flatMap<U>(f: (value: R) => Either<L, U>): Either<L, U>
21
+ }
22
+
23
+ export { Either as E, Left as L, Right as R }
@@ -0,0 +1,10 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+
8
+
9
+
10
+ exports.__publicField = __publicField;
@@ -0,0 +1,10 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+
8
+ export {
9
+ __publicField
10
+ };
@@ -0,0 +1,26 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkGAPG2VLOcjs = require('../chunk-GAPG2VLO.cjs');
4
+ class Left {
5
+ constructor(value) {
6
+ this.value = value;
7
+ _chunkGAPG2VLOcjs.__publicField.call(void 0, this, "tag", "Left");
8
+ }
9
+ isLeft() {
10
+ return true;
11
+ }
12
+ isRight() {
13
+ return false;
14
+ }
15
+ // Transform only the Right value
16
+ map(f) {
17
+ return new Left(this.value);
18
+ }
19
+ // Chain functions that return an Either
20
+ flatMap(f) {
21
+ return new Left(this.value);
22
+ }
23
+ }
24
+
25
+
26
+ exports.Left = Left;
@@ -0,0 +1 @@
1
+ export { L as Left } from '../Left-916151dc.js';
@@ -0,0 +1 @@
1
+ export { L as Left } from "../Left-916151dc.js"
@@ -0,0 +1,26 @@
1
+ import {
2
+ __publicField
3
+ } from "../chunk-KMAXXKJT.js";
4
+ class Left {
5
+ constructor(value) {
6
+ this.value = value;
7
+ __publicField(this, "tag", "Left");
8
+ }
9
+ isLeft() {
10
+ return true;
11
+ }
12
+ isRight() {
13
+ return false;
14
+ }
15
+ // Transform only the Right value
16
+ map(f) {
17
+ return new Left(this.value);
18
+ }
19
+ // Chain functions that return an Either
20
+ flatMap(f) {
21
+ return new Left(this.value);
22
+ }
23
+ }
24
+ export {
25
+ Left
26
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkGAPG2VLOcjs = require('../chunk-GAPG2VLO.cjs');
4
+ class Right {
5
+ constructor(value) {
6
+ this.value = value;
7
+ _chunkGAPG2VLOcjs.__publicField.call(void 0, this, "tag", "Right");
8
+ }
9
+ isLeft() {
10
+ return false;
11
+ }
12
+ isRight() {
13
+ return true;
14
+ }
15
+ map(f) {
16
+ return new Right(f(this.value));
17
+ }
18
+ flatMap(f) {
19
+ return f(this.value);
20
+ }
21
+ }
22
+
23
+
24
+ exports.Right = Right;
@@ -0,0 +1 @@
1
+ export { R as Right } from '../Left-916151dc.js';
@@ -0,0 +1 @@
1
+ export { R as Right } from "../Left-916151dc.js"
@@ -0,0 +1,24 @@
1
+ import {
2
+ __publicField
3
+ } from "../chunk-KMAXXKJT.js";
4
+ class Right {
5
+ constructor(value) {
6
+ this.value = value;
7
+ __publicField(this, "tag", "Right");
8
+ }
9
+ isLeft() {
10
+ return false;
11
+ }
12
+ isRight() {
13
+ return true;
14
+ }
15
+ map(f) {
16
+ return new Right(f(this.value));
17
+ }
18
+ flatMap(f) {
19
+ return f(this.value);
20
+ }
21
+ }
22
+ export {
23
+ Right
24
+ };
@@ -0,0 +1,11 @@
1
+ "use strict";var _Left = require('./Left');
2
+ var _Right = require('./Right');
3
+ const left = (value) => new (0, _Left.Left)(value);
4
+ const right = (value) => new (0, _Right.Right)(value);
5
+ const parseNumber = (input) => {
6
+ const result = parseInt(input, 10);
7
+ if (isNaN(result)) {
8
+ return left("Invalid number");
9
+ }
10
+ return right(result);
11
+ };
@@ -0,0 +1 @@
1
+ export { E as Either } from '../Left-916151dc.js';
@@ -0,0 +1 @@
1
+ export { E as Either } from "../Left-916151dc.js"
@@ -0,0 +1,11 @@
1
+ import { Left } from "./Left";
2
+ import { Right } from "./Right";
3
+ const left = (value) => new Left(value);
4
+ const right = (value) => new Right(value);
5
+ const parseNumber = (input) => {
6
+ const result = parseInt(input, 10);
7
+ if (isNaN(result)) {
8
+ return left("Invalid number");
9
+ }
10
+ return right(result);
11
+ };
package/lib/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/lib/index.js ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "functype",
3
+ "version": "0.0.1",
4
+ "description": "A small functional library for TypeScript",
5
+ "author": "jordan.burke@gmail.com",
6
+ "license": "MIT",
7
+ "url": "https://github.com/jordanburke/TypeScript/tree/main/functype",
8
+ "scripts": {
9
+ "ts-types": "tsc",
10
+ "build:dev": "rimraf lib && tsup --watch",
11
+ "build:prod": "rimraf dist && cross-env NODE_ENV=production tsup",
12
+ "build:watch": "tsup --watch",
13
+ "lint:fix": "eslint ./src --ext .ts,.tsx --quiet --fix --ignore-path ./.gitignore",
14
+ "lint:format": "prettier --loglevel warn --write \"./**/*.{ts,tsx,css,md,json}\" ",
15
+ "lint": "pnpm lint:format && pnpm lint:fix ",
16
+ "test": "jest",
17
+ "test:watch": "jest --watch",
18
+ "test:cov": "jest --coverage"
19
+ },
20
+ "devDependencies": {
21
+ "@types/node": "^18.17.5",
22
+ "@typescript-eslint/eslint-plugin": "^6.4.0",
23
+ "@typescript-eslint/parser": "^6.4.0",
24
+ "@types/jest": "29.5.3",
25
+ "cross-env": "^7.0.3",
26
+ "eslint": "^8.47.0",
27
+ "eslint-config-prettier": "^8.10.0",
28
+ "eslint-plugin-import": "^2.28.0",
29
+ "eslint-plugin-prettier": "^5.0.0",
30
+ "eslint-plugin-simple-import-sort": "^10.0.0",
31
+ "jest": "29.6.2",
32
+ "prettier": "^3.0.2",
33
+ "rimraf": "^5.0.1",
34
+ "tsup": "^7.2.0",
35
+ "ts-jest": "^29.1.1"
36
+ },
37
+ "main": "lib/index.cjs",
38
+ "module": "lib/index.js",
39
+ "types": "lib/index.d.ts",
40
+ "type": "module",
41
+ "dependencies": {
42
+ "typescript": "^5.1.6"
43
+ },
44
+ "files": [
45
+ "lib",
46
+ "dist"
47
+ ]
48
+ }