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,533 lines (1,532 loc) 278 kB
{ "type": "File", "start": 0, "end": 2673, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 76, "column": 0 } }, "program": { "type": "Program", "start": 0, "end": 2673, "loc": { "start": { "line": 1, "column": 0 }, "end": { "line": 76, "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": "Maybe" }, "name": "Maybe" }, "local": { "type": "Identifier", "start": 9, "end": 14, "loc": { "start": { "line": 1, "column": 9 }, "end": { "line": 1, "column": 14 }, "identifierName": "Maybe" }, "name": "Maybe" } } ], "source": { "type": "StringLiteral", "start": 22, "end": 31, "loc": { "start": { "line": 1, "column": 22 }, "end": { "line": 1, "column": 31 } }, "extra": { "rawValue": "./maybe", "raw": "\"./maybe\"" }, "value": "./maybe" } }, { "type": "ImportDeclaration", "start": 34, "end": 67, "loc": { "start": { "line": 2, "column": 0 }, "end": { "line": 2, "column": 33 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 43, "end": 49, "loc": { "start": { "line": 2, "column": 9 }, "end": { "line": 2, "column": 15 } }, "imported": { "type": "Identifier", "start": 43, "end": 49, "loc": { "start": { "line": 2, "column": 9 }, "end": { "line": 2, "column": 15 }, "identifierName": "ErrorM" }, "name": "ErrorM" }, "local": { "type": "Identifier", "start": 43, "end": 49, "loc": { "start": { "line": 2, "column": 9 }, "end": { "line": 2, "column": 15 }, "identifierName": "ErrorM" }, "name": "ErrorM" } } ], "source": { "type": "StringLiteral", "start": 57, "end": 66, "loc": { "start": { "line": 2, "column": 23 }, "end": { "line": 2, "column": 32 } }, "extra": { "rawValue": "./error", "raw": "\"./error\"" }, "value": "./error" } }, { "type": "ImportDeclaration", "start": 69, "end": 110, "loc": { "start": { "line": 3, "column": 0 }, "end": { "line": 3, "column": 41 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 78, "end": 83, "loc": { "start": { "line": 3, "column": 9 }, "end": { "line": 3, "column": 14 } }, "imported": { "type": "Identifier", "start": 78, "end": 83, "loc": { "start": { "line": 3, "column": 9 }, "end": { "line": 3, "column": 14 }, "identifierName": "clone" }, "name": "clone" }, "local": { "type": "Identifier", "start": 78, "end": 83, "loc": { "start": { "line": 3, "column": 9 }, "end": { "line": 3, "column": 14 }, "identifierName": "clone" }, "name": "clone" } } ], "source": { "type": "StringLiteral", "start": 91, "end": 109, "loc": { "start": { "line": 3, "column": 22 }, "end": { "line": 3, "column": 40 } }, "extra": { "rawValue": "./services/clone", "raw": "\"./services/clone\"" }, "value": "./services/clone" } }, { "type": "ImportDeclaration", "start": 112, "end": 159, "loc": { "start": { "line": 4, "column": 0 }, "end": { "line": 4, "column": 47 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 121, "end": 129, "loc": { "start": { "line": 4, "column": 9 }, "end": { "line": 4, "column": 17 } }, "imported": { "type": "Identifier", "start": 121, "end": 129, "loc": { "start": { "line": 4, "column": 9 }, "end": { "line": 4, "column": 17 }, "identifierName": "equality" }, "name": "equality" }, "local": { "type": "Identifier", "start": 121, "end": 129, "loc": { "start": { "line": 4, "column": 9 }, "end": { "line": 4, "column": 17 }, "identifierName": "equality" }, "name": "equality" } } ], "source": { "type": "StringLiteral", "start": 137, "end": 158, "loc": { "start": { "line": 4, "column": 25 }, "end": { "line": 4, "column": 46 } }, "extra": { "rawValue": "./services/equality", "raw": "\"./services/equality\"" }, "value": "./services/equality" } }, { "type": "ImportDeclaration", "start": 161, "end": 193, "loc": { "start": { "line": 5, "column": 0 }, "end": { "line": 5, "column": 32 } }, "specifiers": [ { "type": "ImportSpecifier", "start": 170, "end": 175, "loc": { "start": { "line": 5, "column": 9 }, "end": { "line": 5, "column": 14 } }, "imported": { "type": "Identifier", "start": 170, "end": 175, "loc": { "start": { "line": 5, "column": 9 }, "end": { "line": 5, "column": 14 }, "identifierName": "Monad" }, "name": "Monad" }, "local": { "type": "Identifier", "start": 170, "end": 175, "loc": { "start": { "line": 5, "column": 9 }, "end": { "line": 5, "column": 14 }, "identifierName": "Monad" }, "name": "Monad" } } ], "source": { "type": "StringLiteral", "start": 183, "end": 192, "loc": { "start": { "line": 5, "column": 22 }, "end": { "line": 5, "column": 31 } }, "extra": { "rawValue": "./monad", "raw": "'./monad'" }, "value": "./monad" }, "trailingComments": [ { "type": "CommentBlock", "value": "*\r\n * Class State - it takes a state and returns an intermediate value and some new state value.\r\n * @extends {Monad}\r\n ", "start": 195, "end": 319, "loc": { "start": { "line": 6, "column": 0 }, "end": { "line": 9, "column": 3 } } } ] }, { "type": "ExportNamedDeclaration", "start": 321, "end": 2611, "loc": { "start": { "line": 10, "column": 0 }, "end": { "line": 74, "column": 1 } }, "specifiers": [], "source": null, "declaration": { "type": "ClassDeclaration", "start": 328, "end": 2611, "loc": { "start": { "line": 10, "column": 7 }, "end": { "line": 74, "column": 1 } }, "id": { "type": "Identifier", "start": 334, "end": 339, "loc": { "start": { "line": 10, "column": 13 }, "end": { "line": 10, "column": 18 }, "identifierName": "State" }, "name": "State", "leadingComments": null }, "superClass": { "type": "Identifier", "start": 348, "end": 353, "loc": { "start": { "line": 10, "column": 27 }, "end": { "line": 10, "column": 32 }, "identifierName": "Monad" }, "name": "Monad" }, "body": { "type": "ClassBody", "start": 354, "end": 2611, "loc": { "start": { "line": 10, "column": 33 }, "end": { "line": 74, "column": 1 } }, "body": [ { "type": "ClassMethod", "start": 572, "end": 1002, "loc": { "start": { "line": 15, "column": 4 }, "end": { "line": 32, "column": 5 } }, "computed": false, "key": { "type": "Identifier", "start": 572, "end": 583, "loc": { "start": { "line": 15, "column": 4 }, "end": { "line": 15, "column": 15 }, "identifierName": "constructor" }, "name": "constructor", "leadingComments": null }, "static": false, "kind": "constructor", "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 584, "end": 589, "loc": { "start": { "line": 15, "column": 16 }, "end": { "line": 15, "column": 21 }, "identifierName": "state" }, "name": "state" } ], "body": { "type": "BlockStatement", "start": 591, "end": 1002, "loc": { "start": { "line": 15, "column": 23 }, "end": { "line": 32, "column": 5 } }, "body": [ { "type": "ExpressionStatement", "start": 602, "end": 610, "loc": { "start": { "line": 16, "column": 8 }, "end": { "line": 16, "column": 16 } }, "expression": { "type": "CallExpression", "start": 602, "end": 609, "loc": { "start": { "line": 16, "column": 8 }, "end": { "line": 16, "column": 15 } }, "callee": { "type": "Super", "start": 602, "end": 607, "loc": { "start": { "line": 16, "column": 8 }, "end": { "line": 16, "column": 13 } } }, "arguments": [] }, "trailingComments": [ { "type": "CommentBlock", "value": "*\r\n * Keeps the state of application variables.\r\n * @type {any}\r\n ", "start": 620, "end": 714, "loc": { "start": { "line": 17, "column": 8 }, "end": { "line": 20, "column": 11 } } } ] }, { "type": "ExpressionStatement", "start": 724, "end": 750, "loc": { "start": { "line": 21, "column": 8 }, "end": { "line": 21, "column": 34 } }, "expression": { "type": "AssignmentExpression", "start": 724, "end": 749, "loc": { "start": { "line": 21, "column": 8 }, "end": { "line": 21, "column": 33 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 724, "end": 734, "loc": { "start": { "line": 21, "column": 8 }, "end": { "line": 21, "column": 18 } }, "object": { "type": "ThisExpression", "start": 724, "end": 728, "loc": { "start": { "line": 21, "column": 8 }, "end": { "line": 21, "column": 12 } }, "leadingComments": null }, "property": { "type": "Identifier", "start": 729, "end": 734, "loc": { "start": { "line": 21, "column": 13 }, "end": { "line": 21, "column": 18 }, "identifierName": "state" }, "name": "state" }, "computed": false, "leadingComments": null }, "right": { "type": "CallExpression", "start": 737, "end": 749, "loc": { "start": { "line": 21, "column": 21 }, "end": { "line": 21, "column": 33 } }, "callee": { "type": "Identifier", "start": 737, "end": 742, "loc": { "start": { "line": 21, "column": 21 }, "end": { "line": 21, "column": 26 }, "identifierName": "clone" }, "name": "clone" }, "arguments": [ { "type": "Identifier", "start": 743, "end": 748, "loc": { "start": { "line": 21, "column": 27 }, "end": { "line": 21, "column": 32 }, "identifierName": "state" }, "name": "state" } ] }, "leadingComments": null }, "leadingComments": [ { "type": "CommentBlock", "value": "*\r\n * Keeps the state of application variables.\r\n * @type {any}\r\n ", "start": 620, "end": 714, "loc": { "start": { "line": 17, "column": 8 }, "end": { "line": 20, "column": 11 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\r\n * The instance of Maybe.\r\n * @type {Maybe}\r\n ", "start": 760, "end": 837, "loc": { "start": { "line": 22, "column": 8 }, "end": { "line": 25, "column": 11 } } } ] }, { "type": "ExpressionStatement", "start": 847, "end": 872, "loc": { "start": { "line": 26, "column": 8 }, "end": { "line": 26, "column": 33 } }, "expression": { "type": "AssignmentExpression", "start": 847, "end": 871, "loc": { "start": { "line": 26, "column": 8 }, "end": { "line": 26, "column": 32 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 847, "end": 857, "loc": { "start": { "line": 26, "column": 8 }, "end": { "line": 26, "column": 18 } }, "object": { "type": "ThisExpression", "start": 847, "end": 851, "loc": { "start": { "line": 26, "column": 8 }, "end": { "line": 26, "column": 12 } }, "leadingComments": null }, "property": { "type": "Identifier", "start": 852, "end": 857, "loc": { "start": { "line": 26, "column": 13 }, "end": { "line": 26, "column": 18 }, "identifierName": "maybe" }, "name": "maybe" }, "computed": false, "leadingComments": null }, "right": { "type": "NewExpression", "start": 860, "end": 871, "loc": { "start": { "line": 26, "column": 21 }, "end": { "line": 26, "column": 32 } }, "callee": { "type": "Identifier", "start": 864, "end": 869, "loc": { "start": { "line": 26, "column": 25 }, "end": { "line": 26, "column": 30 }, "identifierName": "Maybe" }, "name": "Maybe" }, "arguments": [] }, "leadingComments": null }, "leadingComments": [ { "type": "CommentBlock", "value": "*\r\n * The instance of Maybe.\r\n * @type {Maybe}\r\n ", "start": 760, "end": 837, "loc": { "start": { "line": 22, "column": 8 }, "end": { "line": 25, "column": 11 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\r\n * The instance of ErrorM.\r\n * @type {ErrorM}\r\n ", "start": 882, "end": 961, "loc": { "start": { "line": 27, "column": 8 }, "end": { "line": 30, "column": 11 } } } ] }, { "type": "ExpressionStatement", "start": 971, "end": 995, "loc": { "start": { "line": 31, "column": 8 }, "end": { "line": 31, "column": 32 } }, "expression": { "type": "AssignmentExpression", "start": 971, "end": 994, "loc": { "start": { "line": 31, "column": 8 }, "end": { "line": 31, "column": 31 } }, "operator": "=", "left": { "type": "MemberExpression", "start": 971, "end": 979, "loc": { "start": { "line": 31, "column": 8 }, "end": { "line": 31, "column": 16 } }, "object": { "type": "ThisExpression", "start": 971, "end": 975, "loc": { "start": { "line": 31, "column": 8 }, "end": { "line": 31, "column": 12 } }, "leadingComments": null }, "property": { "type": "Identifier", "start": 976, "end": 979, "loc": { "start": { "line": 31, "column": 13 }, "end": { "line": 31, "column": 16 }, "identifierName": "err" }, "name": "err" }, "computed": false, "leadingComments": null }, "right": { "type": "NewExpression", "start": 982, "end": 994, "loc": { "start": { "line": 31, "column": 19 }, "end": { "line": 31, "column": 31 } }, "callee": { "type": "Identifier", "start": 986, "end": 992, "loc": { "start": { "line": 31, "column": 23 }, "end": { "line": 31, "column": 29 }, "identifierName": "ErrorM" }, "name": "ErrorM" }, "arguments": [] }, "leadingComments": null }, "leadingComments": [ { "type": "CommentBlock", "value": "*\r\n * The instance of ErrorM.\r\n * @type {ErrorM}\r\n ", "start": 882, "end": 961, "loc": { "start": { "line": 27, "column": 8 }, "end": { "line": 30, "column": 11 } } } ] } ], "directives": [], "trailingComments": null }, "leadingComments": [ { "type": "CommentBlock", "value": "*\r\n * Creates an instance of the class State with an initialization or not, the initialization can be occur late with bind method.\r\n * @param {Object} [state] - the initial state of app.\r\n ", "start": 361, "end": 566, "loc": { "start": { "line": 11, "column": 4 }, "end": { "line": 14, "column": 7 } } } ], "trailingComments": [ { "type": "CommentBlock", "value": "*\r\n * It takes an initial state of the monad if monad has initialized in the constructor then function assigns Error to underlying value.\r\n * @method bind\r\n * @param {Function} f\r\n * @param [v] - underlying value for the monad, it can be null.\r\n ", "start": 1008, "end": 1278, "loc": { "start": { "line": 33, "column": 4 }, "end": { "line": 38, "column": 7 } } } ] }, { "type": "ClassMethod", "start": 1284, "end": 1837, "loc": { "start": { "line": 39, "column": 4 }, "end": { "line": 53, "column": 5 } }, "computed": false, "key": { "type": "Identifier", "start": 1284, "end": 1288, "loc": { "start": { "line": 39, "column": 4 }, "end": { "line": 39, "column": 8 }, "identifierName": "bind" }, "name": "bind", "leadingComments": null }, "static": false, "kind": "method", "id": null, "generator": false, "expression": false, "async": false, "params": [ { "type": "Identifier", "start": 1289, "end": 1290, "loc": { "start": { "line": 39, "column": 9 }, "end": { "line": 39, "column": 10 }, "identifierName": "f" }, "name": "f" }, { "type": "Identifier", "start": 1292, "end": 1293, "loc": { "start": { "line": 39, "column": 12 }, "end": { "line": 39, "column": 13 }, "identifierName": "v" }, "name": "v" } ], "body": { "type": "BlockStatement", "start": 1295, "end": 1837, "loc": { "start": { "line": 39, "column": 15 }, "end": { "line": 53, "column": 5 } }, "body": [ { "type": "VariableDeclaration", "start": 1306, "end": 1333, "loc": { "start": { "line": 40, "column": 8 }, "end": { "line": 40, "column": 35 } }, "declarations": [ { "type": "VariableDeclarator", "start": 1312, "end": 1332, "loc": { "start": { "line": 40, "column": 14 }, "end": { "line": 40, "column": 34 } }, "id": { "type": "Identifier", "start": 1312, "end": 1317, "loc": { "start": { "line": 40, "column": 14 }, "end": { "line": 40, "column": 19 }, "identifierName": "state" }, "name": "state" }, "init": { "type": "UnaryExpression", "start": 1320, "end": 1332, "loc": { "start": { "line": 40, "column": 22 }, "end": { "line": 40, "column": 34 } }, "operator": "!", "prefix": true, "argument": { "type": "UnaryExpression", "start": 1321, "end": 1332, "loc": { "start": { "line": 40, "column": 23 }, "end": { "line": 40, "column": 34 } }, "operator": "!", "prefix": true, "argument": { "type": "MemberExpression", "start": 1322, "end": 1332, "loc": { "start": { "line": 40, "column": 24 }, "end": { "line": 40, "column": 34 } }, "object": { "type": "ThisExpression", "start": 1322, "end": 1326, "loc": { "start": { "line": 40, "column": 24 }, "end": { "line": 40, "column": 28 } } }, "property": { "type": "Identifier", "start": 1327, "end": 1332, "loc": { "start": { "line": 40, "column": 29 }, "end": { "line": 40, "column": 34 }, "identifierName": "state" }, "name": "state" }, "computed": false }, "extra": { "parenthesizedArgument": false } }, "extra": { "parenthesizedArgument": false } } } ], "kind": "const" }, { "type": "VariableDeclaration", "start": 1343, "end": 1358, "loc": { "start": { "line": 41, "column": 8 }, "end": { "line": 41, "column": 23 } }, "declarations": [ { "type": "VariableDeclarator", "start": 1349, "end": 1357, "loc": { "start": { "line": 41, "column": 14 }, "end": { "line": 41, "column": 22 } }, "id": { "type": "Identifier", "start": 1349, "end": 1351, "loc": { "start": { "line": 41, "column": 14 }, "end": { "line": 41, "column": 16 }, "identifierName": "vL" }, "name": "vL" }, "init": { "type": "UnaryExpression", "start": 1354, "end": 1357, "loc": { "start": { "line": 41, "column": 19 }, "end": { "line": 41, "column": 22 } }, "operator": "!", "prefix": true, "argument": { "type": "UnaryExpression", "start": 1355, "end": 1357, "loc": { "start": { "line": 41, "column": 20 }, "end": { "line": 41, "column": 22 } }, "operator": "!", "prefix": true, "argument": { "type": "Identifier", "start": 1356, "end": 1357, "loc": { "start": { "line": 41, "column": 21 }, "end": { "line": 41, "column": 22 }, "identifierName": "v" }, "name": "v" }, "extra": { "parenthesizedArgument": false } }, "extra": { "parenthesizedArgument": false } } } ], "kind": "const" }, { "type": "SwitchStatement", "start": 1368, "end": 1830, "loc": { "start": { "line": 42, "column": 8