UNPKG

monad-ts

Version:

Monad-ts is a small library implements some of key monads and way to chain them in a pipe (flow) in JavaScript and TypeScript. Angular 2+ compatible.

1,345 lines (1,344 loc) 218 kB
{ "type": "File", "start": 0, "end": 1971, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 61, "column": 0 } }, "program": { "type": "Program", "start": 0, "end": 1971, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 61, "column": 0 } }, "sourceType": "module", "body": [ { "type": "ImportDeclaration", "start": 0, "end": 32, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 1, "column": 32 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 9, "end": 14, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 14 } }, "imported": { "type": "Identifier", "start": 9, "end": 14, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 14 }, "identifierName": "Monad" }, "name": "Monad" }, "local": { "type": "Identifier", "start": 9, "end": 14, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 14 }, "identifierName": "Monad" }, "name": "Monad" } } ], "source": { "type": "StringLiteral", "start": 22, "end": 31, "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 31 } }, "extra": { "rawValue": "./monad", "raw": "\"./monad\"" }, "value": "./monad" } }, { "type": "ImportDeclaration", "start": 34, "end": 81, "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 47 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 43, "end": 51, "loc": { "start": { "line": 2, "column": 9 }, "end": { "line": 2, "column": 17 } }, "imported": { "type": "Identifier", "start": 43, "end": 51, "loc": { "start": { "line": 2, "column": 9 }, "end": { "line": 2, "column": 17 }, "identifierName": "equality" }, "name": "equality" }, "local": { "type": "Identifier", "start": 43, "end": 51, "loc": { "start": { "line": 2, "column": 9 }, "end": { "line": 2, "column": 17 }, "identifierName": "equality" }, "name": "equality" } } ], "source": { "type": "StringLiteral", "start": 59, "end": 80, "loc": { "start": { "line": 2, "column": 25 }, "end": { "line": 2, "column": 46 } }, "extra": { "rawValue": "./services/equality", "raw": "\"./services/equality\"" }, "value": "./services/equality" }, "trailingComments": [ { "type": "CommentBlock", "value": "*\r\n * Class Either - represents computation with two possibilities.\r\n * @extends {Monad}\r\n ", "start": 83, "end": 178, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 6, "column": 3 } } } ] }, { "type": "ExportNamedDeclaration", "start": 180, "end": 1908, "loc": { "start": { "line": 7, "column": 0 }, "end": { "line": 59, "column": 1 } }, "specifiers": [], "source": null, "declaration": { "type": "ClassDeclaration", "start": 187, "end": 1908, "loc": { "start": { "line": 7, "column": 7 }, "end": { "line": 59, "column": 1 } }, "id": { "type": "Identifier", "start": 193, "end": 199, "loc": { "start": { "line": 7, "column": 13 }, "end": { "line": 7, "column": 19 }, "identifierName": "Either" }, "name": "Either", "leadingComments": null }, "superClass": { "type": "Identifier", "start": 208, "end": 213, "loc": { "start": { "line": 7, "column": 28 }, "end": { "line": 7, "column": 33 }, "identifierName": "Monad" }, "name": "Monad" }, "body": { "type": "ClassBody", "start": 214, "end": 1908, "loc": { "start": { "line": 7, "column": 34 }, "end": { "line": 59, "column": 1 } }, "body": [ { "type": "ClassMethod", "start": 405, "end": 491, "loc": { "start": { "line": 13, "column": 4 }, "end": { "line": 17, "column": 5 } }, "computed": false, "key": { "type": "Identifier", "start": 405, "end": 416, "loc": { "start": { "line": 13, "column": 4 }, "end": { "line": 13, "column": 15 }, "identifierName": "constructor" }, "name": "constructor", "leadingComments": null }, "static": false, "kind": "constructor", "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 417, "end": 418, "loc": { "start": { "line": 13, "column": 16 }, "end": { "line": 13, "column": 17 }, "identifierName": "r" }, "name": "r" }, { "type": "Identifier", "start": 420, "end": 421, "loc": { "start": { "line": 13, "column": 19 }, "end": { "line": 13, "column": 20 }, "identifierName": "l" }, "name": "l" } ], "body": { "type": "BlockStatement", "start": 423, "end": 491, "loc": { "start": { "line": 13, "column": 22 }, "end": { "line": 17, "column": 5 } }, "body": [ { "type": "ExpressionStatement", "start": 434, "end": 442, "loc": { "start": { "line": 14, "column": 8 }, "end": { "line": 14, "column": 16 } }, "expression": { "type": "CallExpression", "start": 434, "end": 441, "loc": { "start": { "line": 14, "column": 8 }, "end": { "line": 14, "column": 15 } }, "callee": { "type": "Super", "start": 434, "end": 439, "loc": { "start": { "line": 14, "column": 8 }, "end": { "line": 14, "column": 13 } } }, "arguments": [] } }, { "type": "ExpressionStatement", "start": 452, "end": 463, "loc": { "start": { "line": 15, "column": 8 }, "end": { "line": 15, "column": 19 } }, "expression": { "type": "AssignmentExpression", "start": 452, "end": 462, "loc": { "start": { "line": 15, "column": 8 }, "end": { "line": 15, "column": 18 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 452, "end": 458, "loc": { "start": { "line": 15, "column": 8 }, "end": { "line": 15, "column": 14 } }, "object": { "type": "ThisExpression", "start": 452, "end": 456, "loc": { "start": { "line": 15, "column": 8 }, "end": { "line": 15, "column": 12 } } }, "property": { "type": "Identifier", "start": 457, "end": 458, "loc": { "start": { "line": 15, "column": 13 }, "end": { "line": 15, "column": 14 }, "identifierName": "r" }, "name": "r" }, "computed": false }, "right": { "type": "Identifier", "start": 461, "end": 462, "loc": { "start": { "line": 15, "column": 17 }, "end": { "line": 15, "column": 18 }, "identifierName": "r" }, "name": "r" } } }, { "type": "ExpressionStatement", "start": 473, "end": 484, "loc": { "start": { "line": 16, "column": 8 }, "end": { "line": 16, "column": 19 } }, "expression": { "type": "AssignmentExpression", "start": 473, "end": 483, "loc": { "start": { "line": 16, "column": 8 }, "end": { "line": 16, "column": 18 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 473, "end": 479, "loc": { "start": { "line": 16, "column": 8 }, "end": { "line": 16, "column": 14 } }, "object": { "type": "ThisExpression", "start": 473, "end": 477, "loc": { "start": { "line": 16, "column": 8 }, "end": { "line": 16, "column": 12 } } }, "property": { "type": "Identifier", "start": 478, "end": 479, "loc": { "start": { "line": 16, "column": 13 }, "end": { "line": 16, "column": 14 }, "identifierName": "l" }, "name": "l" }, "computed": false }, "right": { "type": "Identifier", "start": 482, "end": 483, "loc": { "start": { "line": 16, "column": 17 }, "end": { "line": 16, "column": 18 }, "identifierName": "l" }, "name": "l" } } } ], "directives": [], "trailingComments": null }, "leadingComments": [ { "type": "CommentBlock", "value": "*\r\n * Creates an instance of class Either.\r\n * @param {function(v: any) => any} r - right function.\r\n * @param {function(v: any) => any} l - left function.\r\n ", "start": 221, "end": 399, "loc": { "start": { "line": 8, "column": 4 }, "end": { "line": 12, "column": 7 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\r\n * Binds controller function and underlying value to the monad.\r\n * @method bind\r\n * @param {D<T>} f - controller function, after execution f(v) produce true (execute right func-n) or false (execute left func-n).\r\n * @param {any} v - underlying value for the monad.\r\n * @return {boolean | Pr<any> | Error}\r\n ", "start": 497, "end": 836, "loc": { "start": { "line": 18, "column": 4 }, "end": { "line": 24, "column": 7 } } } ] }, { "type": "ClassMethod", "start": 842, "end": 1275, "loc": { "start": { "line": 25, "column": 4 }, "end": { "line": 40, "column": 5 } }, "computed": false, "key": { "type": "Identifier", "start": 842, "end": 846, "loc": { "start": { "line": 25, "column": 4 }, "end": { "line": 25, "column": 8 }, "identifierName": "bind" }, "name": "bind", "leadingComments": null }, "static": false, "kind": "method", "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 847, "end": 848, "loc": { "start": { "line": 25, "column": 9 }, "end": { "line": 25, "column": 10 }, "identifierName": "f" }, "name": "f" }, { "type": "Identifier", "start": 850, "end": 851, "loc": { "start": { "line": 25, "column": 12 }, "end": { "line": 25, "column": 13 }, "identifierName": "v" }, "name": "v" } ], "body": { "type": "BlockStatement", "start": 853, "end": 1275, "loc": { "start": { "line": 25, "column": 15 }, "end": { "line": 40, "column": 5 } }, "body": [ { "type": "ExpressionStatement", "start": 864, "end": 878, "loc": { "start": { "line": 26, "column": 8 }, "end": { "line": 26, "column": 22 } }, "expression": { "type": "AssignmentExpression", "start": 864, "end": 877, "loc": { "start": { "line": 26, "column": 8 }, "end": { "line": 26, "column": 21 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 864, "end": 873, "loc": { "start": { "line": 26, "column": 8 }, "end": { "line": 26, "column": 17 } }, "object": { "type": "ThisExpression", "start": 864, "end": 868, "loc": { "start": { "line": 26, "column": 8 }, "end": { "line": 26, "column": 12 } } }, "property": { "type": "Identifier", "start": 869, "end": 873, "loc": { "start": { "line": 26, "column": 13 }, "end": { "line": 26, "column": 17 }, "identifierName": "uVal" }, "name": "uVal" }, "computed": false }, "right": { "type": "Identifier", "start": 876, "end": 877, "loc": { "start": { "line": 26, "column": 20 }, "end": { "line": 26, "column": 21 }, "identifierName": "v" }, "name": "v" } } }, { "type": "TryStatement", "start": 888, "end": 1268, "loc": { "start": { "line": 27, "column": 8 }, "end": { "line": 39, "column": 9 } }, "block": { "type": "BlockStatement", "start": 892, "end": 1181, "loc": { "start": { "line": 27, "column": 12 }, "end": { "line": 36, "column": 9 } }, "body": [ { "type": "SwitchStatement", "start": 907, "end": 1170, "loc": { "start": { "line": 28, "column": 12 }, "end": { "line": 35, "column": 13 } }, "discriminant": { "type": "CallExpression", "start": 915, "end": 919, "loc": { "start": { "line": 28, "column": 20 }, "end": { "line": 28, "column": 24 } }, "callee": { "type": "Identifier", "start": 915, "end": 916, "loc": { "start": { "line": 28, "column": 20 }, "end": { "line": 28, "column": 21 }, "identifierName": "f" }, "name": "f" }, "arguments": [ { "type": "Identifier", "start": 917, "end": 918, "loc": { "start": { "line": 28, "column": 22 }, "end": { "line": 28, "column": 23 }, "identifierName": "v" }, "name": "v" } ] }, "cases": [ { "type": "SwitchCase", "start": 940, "end": 989, "loc": { "start": { "line": 29, "column": 16 }, "end": { "line": 30, "column": 37 } }, "consequent": [ { "type": "ReturnStatement", "start": 972, "end": 989, "loc": { "start": { "line": 30, "column": 20 }, "end": { "line": 30, "column": 37 } }, "argument": { "type": "CallExpression", "start": 979, "end": 988, "loc": { "start": { "line": 30, "column": 27 }, "end": { "line": 30, "column": 36 } }, "callee": { "type": "MemberExpression", "start": 979, "end": 985, "loc": { "start": { "line": 30, "column": 27 }, "end": { "line": 30, "column": 33 } }, "object": { "type": "ThisExpression", "start": 979, "end": 983, "loc": { "start": { "line": 30, "column": 27 }, "end": { "line": 30, "column": 31 } } }, "property": { "type": "Identifier", "start": 984, "end": 985, "loc": { "start": { "line": 30, "column": 32 }, "end": { "line": 30, "column": 33 }, "identifierName": "r" }, "name": "r" }, "computed": false }, "arguments": [ { "type": "Identifier", "start": 986, "end": 987, "loc": { "start": { "line": 30, "column": 34 }, "end": { "line": 30, "column": 35 }, "identifierName": "v" }, "name": "v" } ] } } ], "test": { "type": "BooleanLiteral", "start": 945, "end": 949, "loc": { "start": { "line": 29, "column": 21 }, "end": { "line": 29, "column": 25 } }, "value": true } }, { "type": "SwitchCase", "start": 1007, "end": 1057, "loc": { "start": { "line": 31, "column": 16 }, "end": { "line": 32, "column": 37 } }, "consequent": [ { "type": "ReturnStatement", "start": 1040, "end": 1057, "loc": { "start": { "line": 32, "column": 20 }, "end": { "line": 32, "column": 37 } }, "argument": { "type": "CallExpression", "start": 1047, "end": 1056, "loc": { "start": { "line": 32, "column": 27 }, "end": { "line": 32, "column": 36 } }, "callee": { "type": "MemberExpression", "start": 1047, "end": 1053, "loc": { "start": { "line": 32, "column": 27 }, "end": { "line": 32, "column": 33 } }, "object": { "type": "ThisExpression", "start": 1047, "end": 1051, "loc": { "start": { "line": 32, "column": 27 }, "end": { "line": 32, "column": 31 } } }, "property": { "type": "Identifier", "start": 1052, "end": 1053, "loc": { "start": { "line": 32, "column": 32 }, "end": { "line": 32, "column": 33 }, "identifierName": "l" }, "name": "l" }, "computed": false }, "arguments": [ { "type": "Identifier", "start": 1054, "end": 1055, "loc": { "start": { "line": 32, "column": 34 }, "end": { "line": 32, "column": 35 }, "identifierName": "v" }, "name": "v" } ] } } ], "test": { "type": "BooleanLiteral", "start": 1012, "end": 1017, "loc": { "start": { "line": 31, "column": 21 }, "end": { "line": 31, "column": 26 } }, "value": false } }, { "type": "SwitchCase", "start": 1075, "end": 1155, "loc": { "start": { "line": 33, "column": 16 }, "end": { "line": 34, "column": 70 } }, "consequent": [ { "type": "ReturnStatement", "start": 1105, "end": 1155, "loc": { "start": { "line": 34, "column": 20 }, "end": { "line": 34, "column": 70 } }, "argument": { "type": "CallExpression", "start": 1112, "end": 1154, "loc": { "start": { "line": 34, "column": 27 }, "end": { "line": 34, "column": 69 } }, "callee": { "type": "MemberExpression", "start": 1112, "end": 1121, "loc": { "start": { "line": 34, "column": 27 }, "end": { "line": 34, "column": 36 } }, "object": { "type": "ThisExpression", "start": 1112, "end": 1116, "loc": { "start": { "line": 34, "column": 27 }, "end": { "line": 34, "column": 31 } } }, "property": { "type": "Identifier", "start": 1117, "end": 1121, "loc": { "start": { "line": 34, "column": 32 }, "end": { "line": 34, "column": 36 }, "identifierName": "fail" }, "name": "fail" }, "computed": false }, "arguments": [ { "type": "StringLiteral", "start": 1122, "end": 1153, "loc": { "start": { "line": 34, "column": 37 }, "end": { "line": 34, "column": 68 } }, "extra": { "rawValue": "Either.bind() - binding error", "raw": "'Either.bind() - binding error'" }, "value": "Either.bind() - binding error" } ] } } ], "test": null } ] } ], "directives": [] }, "handler": { "type": "CatchClause", "start": 1191, "end": 1268, "loc": { "start": { "line": 37, "column": 8 }, "end": { "line": 39,