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,488 lines (1,487 loc) • 150 kB
JSON
{
"type": "File",
"start": 0,
"end": 1451,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 46,
"column": 0
}
},
"program": {
"type": "Program",
"start": 0,
"end": 1451,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 46,
"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": 144,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 32
}
},
"specifiers": [
{
"type": "ImportSpecifier",
"start": 121,
"end": 126,
"loc": {
"start": {
"line": 4,
"column": 9
},
"end": {
"line": 4,
"column": 14
}
},
"imported": {
"type": "Identifier",
"start": 121,
"end": 126,
"loc": {
"start": {
"line": 4,
"column": 9
},
"end": {
"line": 4,
"column": 14
},
"identifierName": "Monad"
},
"name": "Monad"
},
"local": {
"type": "Identifier",
"start": 121,
"end": 126,
"loc": {
"start": {
"line": 4,
"column": 9
},
"end": {
"line": 4,
"column": 14
},
"identifierName": "Monad"
},
"name": "Monad"
}
}
],
"source": {
"type": "StringLiteral",
"start": 134,
"end": 143,
"loc": {
"start": {
"line": 4,
"column": 22
},
"end": {
"line": 4,
"column": 31
}
},
"extra": {
"rawValue": "./monad",
"raw": "\"./monad\""
},
"value": "./monad"
},
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Class AsyncFlow - for composing monads in an async flow (pipe), based on Promise.\r\n * @extends {Monad}\r\n ",
"start": 146,
"end": 261,
"loc": {
"start": {
"line": 5,
"column": 0
},
"end": {
"line": 8,
"column": 3
}
}
}
]
},
{
"type": "ExportNamedDeclaration",
"start": 263,
"end": 1388,
"loc": {
"start": {
"line": 9,
"column": 0
},
"end": {
"line": 44,
"column": 1
}
},
"specifiers": [],
"source": null,
"declaration": {
"type": "ClassDeclaration",
"start": 270,
"end": 1388,
"loc": {
"start": {
"line": 9,
"column": 7
},
"end": {
"line": 44,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 276,
"end": 285,
"loc": {
"start": {
"line": 9,
"column": 13
},
"end": {
"line": 9,
"column": 22
},
"identifierName": "AsyncFlow"
},
"name": "AsyncFlow",
"leadingComments": null
},
"superClass": {
"type": "Identifier",
"start": 294,
"end": 299,
"loc": {
"start": {
"line": 9,
"column": 31
},
"end": {
"line": 9,
"column": 36
},
"identifierName": "Monad"
},
"name": "Monad"
},
"body": {
"type": "ClassBody",
"start": 300,
"end": 1388,
"loc": {
"start": {
"line": 9,
"column": 37
},
"end": {
"line": 44,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 558,
"end": 1023,
"loc": {
"start": {
"line": 15,
"column": 4
},
"end": {
"line": 32,
"column": 5
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 558,
"end": 569,
"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": "AssignmentPattern",
"start": 570,
"end": 579,
"loc": {
"start": {
"line": 15,
"column": 16
},
"end": {
"line": 15,
"column": 25
}
},
"left": {
"type": "Identifier",
"start": 570,
"end": 575,
"loc": {
"start": {
"line": 15,
"column": 16
},
"end": {
"line": 15,
"column": 21
},
"identifierName": "initV"
},
"name": "initV"
},
"right": {
"type": "NumericLiteral",
"start": 578,
"end": 579,
"loc": {
"start": {
"line": 15,
"column": 24
},
"end": {
"line": 15,
"column": 25
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
},
{
"type": "AssignmentPattern",
"start": 581,
"end": 599,
"loc": {
"start": {
"line": 15,
"column": 27
},
"end": {
"line": 15,
"column": 45
}
},
"left": {
"type": "Identifier",
"start": 581,
"end": 592,
"loc": {
"start": {
"line": 15,
"column": 27
},
"end": {
"line": 15,
"column": 38
},
"identifierName": "encapsulate"
},
"name": "encapsulate"
},
"right": {
"type": "BooleanLiteral",
"start": 595,
"end": 599,
"loc": {
"start": {
"line": 15,
"column": 41
},
"end": {
"line": 15,
"column": 45
}
},
"value": true
}
}
],
"body": {
"type": "BlockStatement",
"start": 601,
"end": 1023,
"loc": {
"start": {
"line": 15,
"column": 47
},
"end": {
"line": 32,
"column": 5
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 612,
"end": 620,
"loc": {
"start": {
"line": 16,
"column": 8
},
"end": {
"line": 16,
"column": 16
}
},
"expression": {
"type": "CallExpression",
"start": 612,
"end": 619,
"loc": {
"start": {
"line": 16,
"column": 8
},
"end": {
"line": 16,
"column": 15
}
},
"callee": {
"type": "Super",
"start": 612,
"end": 617,
"loc": {
"start": {
"line": 16,
"column": 8
},
"end": {
"line": 16,
"column": 13
}
}
},
"arguments": []
},
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Keep initial flow (pipe) value.\r\n * @type {any}\r\n ",
"start": 630,
"end": 714,
"loc": {
"start": {
"line": 17,
"column": 8
},
"end": {
"line": 20,
"column": 11
}
}
}
]
},
{
"type": "ExpressionStatement",
"start": 724,
"end": 771,
"loc": {
"start": {
"line": 21,
"column": 8
},
"end": {
"line": 21,
"column": 55
}
},
"expression": {
"type": "AssignmentExpression",
"start": 724,
"end": 770,
"loc": {
"start": {
"line": 21,
"column": 8
},
"end": {
"line": 21,
"column": 54
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 724,
"end": 733,
"loc": {
"start": {
"line": 21,
"column": 8
},
"end": {
"line": 21,
"column": 17
}
},
"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": 733,
"loc": {
"start": {
"line": 21,
"column": 13
},
"end": {
"line": 21,
"column": 17
},
"identifierName": "flow"
},
"name": "flow"
},
"computed": false,
"leadingComments": null
},
"right": {
"type": "ConditionalExpression",
"start": 736,
"end": 770,
"loc": {
"start": {
"line": 21,
"column": 20
},
"end": {
"line": 21,
"column": 54
}
},
"test": {
"type": "Identifier",
"start": 736,
"end": 747,
"loc": {
"start": {
"line": 21,
"column": 20
},
"end": {
"line": 21,
"column": 31
},
"identifierName": "encapsulate"
},
"name": "encapsulate"
},
"consequent": {
"type": "CallExpression",
"start": 750,
"end": 762,
"loc": {
"start": {
"line": 21,
"column": 34
},
"end": {
"line": 21,
"column": 46
}
},
"callee": {
"type": "Identifier",
"start": 750,
"end": 755,
"loc": {
"start": {
"line": 21,
"column": 34
},
"end": {
"line": 21,
"column": 39
},
"identifierName": "clone"
},
"name": "clone"
},
"arguments": [
{
"type": "Identifier",
"start": 756,
"end": 761,
"loc": {
"start": {
"line": 21,
"column": 40
},
"end": {
"line": 21,
"column": 45
},
"identifierName": "initV"
},
"name": "initV"
}
]
},
"alternate": {
"type": "Identifier",
"start": 765,
"end": 770,
"loc": {
"start": {
"line": 21,
"column": 49
},
"end": {
"line": 21,
"column": 54
},
"identifierName": "initV"
},
"name": "initV"
}
},
"leadingComments": null
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Keep initial flow (pipe) value.\r\n * @type {any}\r\n ",
"start": 630,
"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": 781,
"end": 858,
"loc": {
"start": {
"line": 22,
"column": 8
},
"end": {
"line": 25,
"column": 11
}
}
}
]
},
{
"type": "ExpressionStatement",
"start": 868,
"end": 893,
"loc": {
"start": {
"line": 26,
"column": 8
},
"end": {
"line": 26,
"column": 33
}
},
"expression": {
"type": "AssignmentExpression",
"start": 868,
"end": 892,
"loc": {
"start": {
"line": 26,
"column": 8
},
"end": {
"line": 26,
"column": 32
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 868,
"end": 878,
"loc": {
"start": {
"line": 26,
"column": 8
},
"end": {
"line": 26,
"column": 18
}
},
"object": {
"type": "ThisExpression",
"start": 868,
"end": 872,
"loc": {
"start": {
"line": 26,
"column": 8
},
"end": {
"line": 26,
"column": 12
}
},
"leadingComments": null
},
"property": {
"type": "Identifier",
"start": 873,
"end": 878,
"loc": {
"start": {
"line": 26,
"column": 13
},
"end": {
"line": 26,
"column": 18
},
"identifierName": "maybe"
},
"name": "maybe"
},
"computed": false,
"leadingComments": null
},
"right": {
"type": "NewExpression",
"start": 881,
"end": 892,
"loc": {
"start": {
"line": 26,
"column": 21
},
"end": {
"line": 26,
"column": 32
}
},
"callee": {
"type": "Identifier",
"start": 885,
"end": 890,
"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": 781,
"end": 858,
"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": 903,
"end": 982,
"loc": {
"start": {
"line": 27,
"column": 8
},
"end": {
"line": 30,
"column": 11
}
}
}
]
},
{
"type": "ExpressionStatement",
"start": 992,
"end": 1016,
"loc": {
"start": {
"line": 31,
"column": 8
},
"end": {
"line": 31,
"column": 32
}
},
"expression": {
"type": "AssignmentExpression",
"start": 992,
"end": 1015,
"loc": {
"start": {
"line": 31,
"column": 8
},
"end": {
"line": 31,
"column": 31
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 992,
"end": 1000,
"loc": {
"start": {
"line": 31,
"column": 8
},
"end": {
"line": 31,
"column": 16
}
},
"object": {
"type": "ThisExpression",
"start": 992,
"end": 996,
"loc": {
"start": {
"line": 31,
"column": 8
},
"end": {
"line": 31,
"column": 12
}
},
"leadingComments": null
},
"property": {
"type": "Identifier",
"start": 997,
"end": 1000,
"loc": {
"start": {
"line": 31,
"column": 13
},
"end": {
"line": 31,
"column": 16
},
"identifierName": "err"
},
"name": "err"
},
"computed": false,
"leadingComments": null
},
"right": {
"type": "NewExpression",
"start": 1003,
"end": 1015,
"loc": {
"start": {
"line": 31,
"column": 19
},
"end": {
"line": 31,
"column": 31
}
},
"callee": {
"type": "Identifier",
"start": 1007,
"end": 1013,
"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": 903,
"end": 982,
"loc": {
"start": {
"line": 27,
"column": 8
},
"end": {
"line": 30,
"column": 11
}
}
}
]
}
],
"directives": [],
"trailingComments": null
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Creates an instance of class AsyncFlow.\r\n * @param {any} [initV = 0] initV - initial value of new flow (pipe).\r\n * @param {boolean} [encapsulate = true] encapsulate - flag, if true then the init value will be cloned.\r\n ",
"start": 307,
"end": 552,
"loc": {
"start": {
"line": 10,
"column": 4
},
"end": {
"line": 14,
"column": 7
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Binds initial value to the transformation function.\r\n * @method bind\r\n * @param {function(v: T) => Pr<U>} f - transformation function.\r\n * @return {Promise<T>}\r\n ",
"start": 1029,
"end": 1221,
"loc": {
"start": {
"line": 33,
"column": 4
},
"end": {
"line": 38,
"column": 7
}
}
}
]
},
{
"type": "ClassMethod",
"start": 1227,
"end": 1385,
"loc": {
"start": {
"line": 39,
"column": 4
},
"end": {
"line": 43,
"column": 5
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 1227,
"end": 1231,
"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": 1232,
"end": 1233,
"loc": {
"start": {
"line": 39,
"column": 9
},
"end": {
"line": 39,
"column": 10
},
"identifierName": "f"
},
"name": "f"
}
],
"body": {
"type": "BlockStatement",
"start": 1235,
"end": 1385,
"loc": {
"start": {
"line": 39,
"column": 12
},
"end": {
"line": 43,
"column": 5
}
},
"body": [
{
"type": "ReturnStatement",
"start": 1246,
"end": 1378,
"loc": {
"start": {
"line": 40,
"column": 8
},
"end": {
"line": 42,
"column": 11
}
},
"argument": {
"type": "NewExpression",
"start": 1253,
"end": 1377,
"loc": {
"start": {
"line": 40,
"column": 15
},
"end": {
"line": 42,
"column": 10
}
},
"callee": {
"type": "Identifier",
"start": 1257,
"end": 1264,
"loc": {
"start": {
"line": 40,
"column": 19
},
"end": {
"line": 40,
"column": 26
},
"identifierName": "Promise"
},
"name": "Promise"
},
"arguments": [
{
"type": "ArrowFunctionExpression",
"start": 1265,
"end": 1376,
"loc": {
"start": {
"line": 40,
"column": 27
},
"end": {
"line": 42,
"column": 9
}
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 1266,
"end": 1273,
"loc": {
"start": {
"line": 40,
"column": 28
},
"end": {
"line": 40,
"column": 35
},
"identifierName": "resolve"
},
"name": "resolve"
}
],
"body": {
"type": "BlockStatement",
"start": 1278,
"end": 1376,
"loc": {
"start": {
"line": 40,
"column": 40
},
"end": {
"line": 42,
"column": 9
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 1293,
"end": 1365,
"loc": {
"start": {
"line": 41,
"column": 12
},
"end": {
"line": 41,
"column": 84
}
},
"expression": {
"type": "CallExpression",
"start": 1293,
"end": 1364,
"loc": {
"start": {
"line": 41,
"column": 12
},
"end": {
"line": 41,
"column": 83
}
},
"callee": {
"type": "Identifier",
"start": 1293,
"end": 1300,
"loc": {
"start": {
"line": 41,
"column": 12
},
"end": {
"line": 41,
"column": 19
},
"identifierName": "resolve"
},
"name": "resolve"
},
"arguments": [
{
"type": "CallExpression",
"start": 1301,
"end": 1363,
"loc": {
"start": {
"line": 41,
"column": 20
},
"end": {
"line": 41,
"column": 82
}
},
"callee": {
"type": "MemberExpression",
"start": 1301,
"end": 1314,
"loc": {
"start": {
"line": 41,
"column": 20
},
"end": {
"line": 41,
"column": 33
}
},
"object": {
"type": "MemberExpression",
"start": 1301,
"end": 1309,
"loc": {
"start": {
"line": 41,