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,487 lines (1,486 loc) • 137 kB
JSON
{
"type": "File",
"start": 0,
"end": 1427,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 45,
"column": 0
}
},
"program": {
"type": "Program",
"start": 0,
"end": 1427,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 45,
"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": 75,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 2,
"column": 41
}
},
"specifiers": [
{
"type": "ImportSpecifier",
"start": 43,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 14
}
},
"imported": {
"type": "Identifier",
"start": 43,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 14
},
"identifierName": "clone"
},
"name": "clone"
},
"local": {
"type": "Identifier",
"start": 43,
"end": 48,
"loc": {
"start": {
"line": 2,
"column": 9
},
"end": {
"line": 2,
"column": 14
},
"identifierName": "clone"
},
"name": "clone"
}
}
],
"source": {
"type": "StringLiteral",
"start": 56,
"end": 74,
"loc": {
"start": {
"line": 2,
"column": 22
},
"end": {
"line": 2,
"column": 40
}
},
"extra": {
"rawValue": "./services/clone",
"raw": "\"./services/clone\""
},
"value": "./services/clone"
}
},
{
"type": "ImportDeclaration",
"start": 77,
"end": 124,
"loc": {
"start": {
"line": 3,
"column": 0
},
"end": {
"line": 3,
"column": 47
}
},
"specifiers": [
{
"type": "ImportSpecifier",
"start": 86,
"end": 94,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 17
}
},
"imported": {
"type": "Identifier",
"start": 86,
"end": 94,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 17
},
"identifierName": "equality"
},
"name": "equality"
},
"local": {
"type": "Identifier",
"start": 86,
"end": 94,
"loc": {
"start": {
"line": 3,
"column": 9
},
"end": {
"line": 3,
"column": 17
},
"identifierName": "equality"
},
"name": "equality"
}
}
],
"source": {
"type": "StringLiteral",
"start": 102,
"end": 123,
"loc": {
"start": {
"line": 3,
"column": 25
},
"end": {
"line": 3,
"column": 46
}
},
"extra": {
"rawValue": "./services/equality",
"raw": "\"./services/equality\""
},
"value": "./services/equality"
}
},
{
"type": "ImportDeclaration",
"start": 126,
"end": 159,
"loc": {
"start": {
"line": 4,
"column": 0
},
"end": {
"line": 4,
"column": 33
}
},
"specifiers": [
{
"type": "ImportSpecifier",
"start": 135,
"end": 141,
"loc": {
"start": {
"line": 4,
"column": 9
},
"end": {
"line": 4,
"column": 15
}
},
"imported": {
"type": "Identifier",
"start": 135,
"end": 141,
"loc": {
"start": {
"line": 4,
"column": 9
},
"end": {
"line": 4,
"column": 15
},
"identifierName": "ErrorM"
},
"name": "ErrorM"
},
"local": {
"type": "Identifier",
"start": 135,
"end": 141,
"loc": {
"start": {
"line": 4,
"column": 9
},
"end": {
"line": 4,
"column": 15
},
"identifierName": "ErrorM"
},
"name": "ErrorM"
}
}
],
"source": {
"type": "StringLiteral",
"start": 149,
"end": 158,
"loc": {
"start": {
"line": 4,
"column": 23
},
"end": {
"line": 4,
"column": 32
}
},
"extra": {
"rawValue": "./error",
"raw": "\"./error\""
},
"value": "./error"
},
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Class Identity - wraps underlying value into the monadic value and compute results from a monadic value.\r\n * @extends {Monad}\r\n ",
"start": 161,
"end": 299,
"loc": {
"start": {
"line": 5,
"column": 0
},
"end": {
"line": 8,
"column": 3
}
}
}
]
},
{
"type": "ExportNamedDeclaration",
"start": 301,
"end": 1365,
"loc": {
"start": {
"line": 9,
"column": 0
},
"end": {
"line": 43,
"column": 1
}
},
"specifiers": [],
"source": null,
"declaration": {
"type": "ClassDeclaration",
"start": 308,
"end": 1365,
"loc": {
"start": {
"line": 9,
"column": 7
},
"end": {
"line": 43,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 314,
"end": 322,
"loc": {
"start": {
"line": 9,
"column": 13
},
"end": {
"line": 9,
"column": 21
},
"identifierName": "Identity"
},
"name": "Identity",
"leadingComments": null
},
"superClass": {
"type": "Identifier",
"start": 331,
"end": 336,
"loc": {
"start": {
"line": 9,
"column": 30
},
"end": {
"line": 9,
"column": 35
},
"identifierName": "Monad"
},
"name": "Monad"
},
"body": {
"type": "ClassBody",
"start": 337,
"end": 1365,
"loc": {
"start": {
"line": 9,
"column": 36
},
"end": {
"line": 43,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 464,
"end": 753,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 26,
"column": 5
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 464,
"end": 475,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 14,
"column": 15
},
"identifierName": "constructor"
},
"name": "constructor",
"leadingComments": null
},
"static": false,
"kind": "constructor",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 476,
"end": 477,
"loc": {
"start": {
"line": 14,
"column": 16
},
"end": {
"line": 14,
"column": 17
},
"identifierName": "v"
},
"name": "v"
}
],
"body": {
"type": "BlockStatement",
"start": 479,
"end": 753,
"loc": {
"start": {
"line": 14,
"column": 19
},
"end": {
"line": 26,
"column": 5
}
},
"body": [
{
"type": "ExpressionStatement",
"start": 490,
"end": 498,
"loc": {
"start": {
"line": 15,
"column": 8
},
"end": {
"line": 15,
"column": 16
}
},
"expression": {
"type": "CallExpression",
"start": 490,
"end": 497,
"loc": {
"start": {
"line": 15,
"column": 8
},
"end": {
"line": 15,
"column": 15
}
},
"callee": {
"type": "Super",
"start": 490,
"end": 495,
"loc": {
"start": {
"line": 15,
"column": 8
},
"end": {
"line": 15,
"column": 13
}
}
},
"arguments": []
},
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Keeps underlying value of a monad.\r\n * @type {any}\r\n ",
"start": 508,
"end": 595,
"loc": {
"start": {
"line": 16,
"column": 8
},
"end": {
"line": 19,
"column": 11
}
}
}
]
},
{
"type": "ExpressionStatement",
"start": 605,
"end": 623,
"loc": {
"start": {
"line": 20,
"column": 8
},
"end": {
"line": 20,
"column": 26
}
},
"expression": {
"type": "AssignmentExpression",
"start": 605,
"end": 622,
"loc": {
"start": {
"line": 20,
"column": 8
},
"end": {
"line": 20,
"column": 25
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 605,
"end": 611,
"loc": {
"start": {
"line": 20,
"column": 8
},
"end": {
"line": 20,
"column": 14
}
},
"object": {
"type": "ThisExpression",
"start": 605,
"end": 609,
"loc": {
"start": {
"line": 20,
"column": 8
},
"end": {
"line": 20,
"column": 12
}
},
"leadingComments": null
},
"property": {
"type": "Identifier",
"start": 610,
"end": 611,
"loc": {
"start": {
"line": 20,
"column": 13
},
"end": {
"line": 20,
"column": 14
},
"identifierName": "v"
},
"name": "v"
},
"computed": false,
"leadingComments": null
},
"right": {
"type": "CallExpression",
"start": 614,
"end": 622,
"loc": {
"start": {
"line": 20,
"column": 17
},
"end": {
"line": 20,
"column": 25
}
},
"callee": {
"type": "Identifier",
"start": 614,
"end": 619,
"loc": {
"start": {
"line": 20,
"column": 17
},
"end": {
"line": 20,
"column": 22
},
"identifierName": "clone"
},
"name": "clone"
},
"arguments": [
{
"type": "Identifier",
"start": 620,
"end": 621,
"loc": {
"start": {
"line": 20,
"column": 23
},
"end": {
"line": 20,
"column": 24
},
"identifierName": "v"
},
"name": "v"
}
]
},
"leadingComments": null
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Keeps underlying value of a monad.\r\n * @type {any}\r\n ",
"start": 508,
"end": 595,
"loc": {
"start": {
"line": 16,
"column": 8
},
"end": {
"line": 19,
"column": 11
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * The instance of ErrorM.\r\n * @type {ErrorM}\r\n ",
"start": 633,
"end": 712,
"loc": {
"start": {
"line": 21,
"column": 8
},
"end": {
"line": 24,
"column": 11
}
}
}
]
},
{
"type": "ExpressionStatement",
"start": 722,
"end": 746,
"loc": {
"start": {
"line": 25,
"column": 8
},
"end": {
"line": 25,
"column": 32
}
},
"expression": {
"type": "AssignmentExpression",
"start": 722,
"end": 745,
"loc": {
"start": {
"line": 25,
"column": 8
},
"end": {
"line": 25,
"column": 31
}
},
"operator": "=",
"left": {
"type": "MemberExpression",
"start": 722,
"end": 730,
"loc": {
"start": {
"line": 25,
"column": 8
},
"end": {
"line": 25,
"column": 16
}
},
"object": {
"type": "ThisExpression",
"start": 722,
"end": 726,
"loc": {
"start": {
"line": 25,
"column": 8
},
"end": {
"line": 25,
"column": 12
}
},
"leadingComments": null
},
"property": {
"type": "Identifier",
"start": 727,
"end": 730,
"loc": {
"start": {
"line": 25,
"column": 13
},
"end": {
"line": 25,
"column": 16
},
"identifierName": "err"
},
"name": "err"
},
"computed": false,
"leadingComments": null
},
"right": {
"type": "NewExpression",
"start": 733,
"end": 745,
"loc": {
"start": {
"line": 25,
"column": 19
},
"end": {
"line": 25,
"column": 31
}
},
"callee": {
"type": "Identifier",
"start": 737,
"end": 743,
"loc": {
"start": {
"line": 25,
"column": 23
},
"end": {
"line": 25,
"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": 633,
"end": 712,
"loc": {
"start": {
"line": 21,
"column": 8
},
"end": {
"line": 24,
"column": 11
}
}
}
]
}
],
"directives": [],
"trailingComments": null
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Creates an instance of class Identity.\r\n * @param {any} [v] - The initial state of app.\r\n * ",
"start": 344,
"end": 458,
"loc": {
"start": {
"line": 10,
"column": 4
},
"end": {
"line": 13,
"column": 9
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Chains the operations on a monadic value.\r\n * @method bind\r\n * @param {MF<T, U>} f - transformation function for the monad.\r\n * @param {any} [v = this.v]- underlying value for the monad, it can be null.\r\n * @return {Pr<U> | Error}\r\n ",
"start": 759,
"end": 1026,
"loc": {
"start": {
"line": 27,
"column": 4
},
"end": {
"line": 33,
"column": 7
}
}
}
]
},
{
"type": "ClassMethod",
"start": 1032,
"end": 1362,
"loc": {
"start": {
"line": 34,
"column": 4
},
"end": {
"line": 42,
"column": 5
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 1032,
"end": 1036,
"loc": {
"start": {
"line": 34,
"column": 4
},
"end": {
"line": 34,
"column": 8
},
"identifierName": "bind"
},
"name": "bind",
"leadingComments": null
},
"static": false,
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 1037,
"end": 1038,
"loc": {
"start": {
"line": 34,
"column": 9
},
"end": {
"line": 34,
"column": 10
},
"identifierName": "f"
},
"name": "f"
},
{
"type": "AssignmentPattern",
"start": 1040,
"end": 1050,
"loc": {
"start": {
"line": 34,
"column": 12
},
"end": {
"line": 34,
"column": 22
}
},
"left": {
"type": "Identifier",
"start": 1040,
"end": 1041,
"loc": {
"start": {
"line": 34,
"column": 12
},
"end": {
"line": 34,
"column": 13
},
"identifierName": "v"
},
"name": "v"
},
"right": {
"type": "MemberExpression",
"start": 1044,
"end": 1050,
"loc": {
"start": {
"line": 34,
"column": 16
},
"end": {
"line": 34,
"column": 22
}
},
"object": {
"type": "ThisExpression",
"start": 1044,
"end": 1048,
"loc": {
"start": {
"line": 34,
"column": 16
},
"end": {
"line": 34,
"column": 20
}
}
},
"property": {
"type": "Identifier",
"start": 1049,
"end": 1050,
"loc": {
"start": {
"line": 34,
"column": 21
},
"end": {
"line": 34,
"column": 22
},
"identifierName": "v"
},
"name": "v"
},
"computed": false
}
}
],
"body": {
"type": "BlockStatement",
"start": 1052,
"end": 1362,
"loc": {
"start": {
"line": 34,
"column": 24
},
"end": {
"line": 42,
"column": 5
}
},
"body": [
{
"type": "ReturnStatement",
"start": 1063,
"end": 1355,
"loc": {
"start": {
"line": 35,
"column": 8
},
"end": {
"line": 41,
"column": 22
}
},
"argument": {
"type": "ConditionalExpression",
"start": 1070,
"end": 1354,
"loc": {
"start": {
"line": 35,
"column": 15
},
"end": {
"line": 41,
"column": 21
}
},
"test": {
"type": "LogicalExpression",
"start": 1070,
"end": 1081,
"loc": {
"start": {
"line": 35,
"column": 15
},
"end": {
"line": 35,
"column": 26
}
},
"left": {
"type": "MemberExpression",
"start": 1070,
"end": 1076,
"loc": {
"start": {
"line": 35,
"column": 15
},
"end": {
"line": 35,
"column": 21
}
},
"object": {
"type": "ThisExpression",
"start": 1070,
"end": 1074,
"loc": {
"start": {
"line": 35,
"column": 15
},
"end": {
"line": 35,
"column": 19
}
}
},
"property": {
"type": "Identifier",
"start": 1075,
"end": 1076,
"loc": {
"start": {
"line": 35,
"column": 20
},
"end": {
"line": 35,
"column": 21
},
"identifierName": "v"
},
"name": "v"
},
"computed": false
},
"operator": "&&",
"right": {
"type": "Identifier",
"start": 1080,
"end": 1081,
"loc": {
"start": {
"line": 35,
"column": 25
},
"end": {
"line": 35,
"column": 26
},
"identifierName": "v"
},
"name": "v"
}
},
"consequent": {
"type": "ConditionalExpression",
"start": 1097,
"end": 1253,
"loc": {
"start": {
"line": 36,
"column": 14
},
"end": {
"line": 38,
"column": 111
}
},
"test": {
"type": "CallExpression",
"start": 1097,
"end": 1116,
"loc": {
"start": {
"line": 36,
"column": 14
},
"end": {
"line": 36,
"column": 33
}
},
"callee": {
"type": "Identifier",
"start": 1097,
"end": 1105,
"loc": {
"start": {
"line": 36,
"column": 14
},
"end": {
"line": 36,
"column": 22
},
"identifierName": "equality"
},
"name": "equality"
},
"arguments": [
{
"type": "MemberExpression",
"start": 1106,
"end": 1112,
"loc": {
"start": {
"line": 36,
"column": 23
},
"end": {
"line": 36,
"column": 29
}
},
"object": {
"type": "ThisExpression",
"start": 1106,
"end": 1110,
"loc": {
"start": {
"line": 36,
"column": 23
},
"end": {
"line": 36,
"column": 27
}
}
},
"property": {
"type": "Identifier",
"start": 1111,
"end": 1112,
"loc": {
"start": {
"line": 36,
"column": 28
},
"end": {
"line": 36,
"column": 29
},
"identifierName": "v"
},
"name": "v"
},
"computed": false
},
{
"type": "Identifier",
"start": 1114,
"end": 1115,
"loc": {
"start": {
"line": 36,
"column": 31
},
"end": {
"line": 36,
"column": 32
},
"identifierName": "v"
},
"name": "v"
}
]
},
"consequent": {
"type": "CallExpression",
"start": 1136,
"end": 1140,
"loc": {
"start": {
"line": 37,
"column": 18
},
"end": {
"line": 37,
"column": 22
}
},
"callee": {
"type": "Identifier",
"start": 1136,
"end": 1137,
"loc": {
"start": {
"line": 37,
"column": 18
},
"end": {
"line": 37,
"column": 19
},
"identifierName": "f"
},
"name": "f"
},
"arguments": [
{
"type": "Identifier",
"start": 1138,
"end": 1139,
"loc": {
"start": {
"line": 37,
"column": 20
},
"end": {
"line": 37,
"column": 21
},
"identifierName": "v"
},
"name": "v"
}
]
},
"alternate": {
"type": "CallExpression",
"start": 1160,
"end": 1253,
"loc": {
"start": {
"line": 38,
"column": 18
},
"end": {
"line": 38,
"column": 111
}
},
"callee": {
"type": "MemberExpression",
"start": 1160,
"end": 1169,
"loc": {
"start": {
"line": 38,
"column": 18
},
"end": {
"line": 38,
"column": 27
}
},
"object": {
"type": "ThisExpression",
"start": 1160,
"end": 1164,
"loc": {
"start": {
"line": 38,
"column": 18
},
"end": {
"line": 38,
"column": 22
}
}
},
"property": {
"type": "Identifier",
"start": 1165,
"end": 1169,
"loc": {
"start": {
"line": 38,
"column": 23
},
"end": {
"line": 38,
"column": 27
},
"identifierName": "fail"
},
"name": "fail"
},
"computed": false
},
"arguments": [
{
"type": "StringLiteral",
"start": 1170,
"end": 1252,
"loc": {
"start": {
"line": 38,
"column": 28
},
"end": {
"line": 38,
"column": 110
}
},
"extra": {
"rawValue": "Identity.bind() - underlying value of the monad have defined in the constructor!",
"raw": "'Identity.bind() - underlying value of the monad have defined in the constructor!'"
},
"value": "Identity.bind() - underlying value of the monad have defined in the constructor!"
}
]
}
},
"alternate": {
"type": "ConditionalExpression",
"start": 1269,
"end": 1354,
"loc": {
"start": {
"line": 39,
"column": 14
},
"end": {
"line": 41,
"column": 21
}
},
"test": {
"type": "LogicalExpression",
"start": 1269,
"end": 1307,
"loc": {
"start": {
"line": 39,
"column": 14