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,564 lines (1,563 loc) • 113 kB
JSON
{
"type": "File",
"start": 0,
"end": 1024,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 38,
"column": 0
}
},
"program": {
"type": "Program",
"start": 0,
"end": 1024,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 38,
"column": 0
}
},
"sourceType": "module",
"body": [
{
"type": "ExportNamedDeclaration",
"start": 188,
"end": 406,
"loc": {
"start": {
"line": 8,
"column": 0
},
"end": {
"line": 12,
"column": 1
}
},
"specifiers": [],
"source": null,
"declaration": {
"type": "FunctionDeclaration",
"start": 195,
"end": 406,
"loc": {
"start": {
"line": 8,
"column": 7
},
"end": {
"line": 12,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 204,
"end": 208,
"loc": {
"start": {
"line": 8,
"column": 16
},
"end": {
"line": 8,
"column": 20
},
"identifierName": "cast"
},
"name": "cast",
"leadingComments": null
},
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 209,
"end": 212,
"loc": {
"start": {
"line": 8,
"column": 21
},
"end": {
"line": 8,
"column": 24
},
"identifierName": "arr"
},
"name": "arr"
},
{
"type": "AssignmentPattern",
"start": 214,
"end": 219,
"loc": {
"start": {
"line": 8,
"column": 26
},
"end": {
"line": 8,
"column": 31
}
},
"left": {
"type": "Identifier",
"start": 214,
"end": 215,
"loc": {
"start": {
"line": 8,
"column": 26
},
"end": {
"line": 8,
"column": 27
},
"identifierName": "n"
},
"name": "n"
},
"right": {
"type": "NumericLiteral",
"start": 218,
"end": 219,
"loc": {
"start": {
"line": 8,
"column": 30
},
"end": {
"line": 8,
"column": 31
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
}
],
"body": {
"type": "BlockStatement",
"start": 221,
"end": 406,
"loc": {
"start": {
"line": 8,
"column": 33
},
"end": {
"line": 12,
"column": 1
}
},
"body": [
{
"type": "ReturnStatement",
"start": 228,
"end": 403,
"loc": {
"start": {
"line": 9,
"column": 4
},
"end": {
"line": 11,
"column": 81
}
},
"argument": {
"type": "ConditionalExpression",
"start": 235,
"end": 402,
"loc": {
"start": {
"line": 9,
"column": 11
},
"end": {
"line": 11,
"column": 80
}
},
"test": {
"type": "LogicalExpression",
"start": 235,
"end": 278,
"loc": {
"start": {
"line": 9,
"column": 11
},
"end": {
"line": 9,
"column": 54
}
},
"left": {
"type": "BinaryExpression",
"start": 235,
"end": 256,
"loc": {
"start": {
"line": 9,
"column": 11
},
"end": {
"line": 9,
"column": 32
}
},
"left": {
"type": "UnaryExpression",
"start": 235,
"end": 243,
"loc": {
"start": {
"line": 9,
"column": 11
},
"end": {
"line": 9,
"column": 19
}
},
"operator": "typeof",
"prefix": true,
"argument": {
"type": "Identifier",
"start": 242,
"end": 243,
"loc": {
"start": {
"line": 9,
"column": 18
},
"end": {
"line": 9,
"column": 19
},
"identifierName": "n"
},
"name": "n"
},
"extra": {
"parenthesizedArgument": false
}
},
"operator": "===",
"right": {
"type": "StringLiteral",
"start": 248,
"end": 256,
"loc": {
"start": {
"line": 9,
"column": 24
},
"end": {
"line": 9,
"column": 32
}
},
"extra": {
"rawValue": "number",
"raw": "'number'"
},
"value": "number"
}
},
"operator": "&&",
"right": {
"type": "CallExpression",
"start": 260,
"end": 278,
"loc": {
"start": {
"line": 9,
"column": 36
},
"end": {
"line": 9,
"column": 54
}
},
"callee": {
"type": "MemberExpression",
"start": 260,
"end": 273,
"loc": {
"start": {
"line": 9,
"column": 36
},
"end": {
"line": 9,
"column": 49
}
},
"object": {
"type": "Identifier",
"start": 260,
"end": 265,
"loc": {
"start": {
"line": 9,
"column": 36
},
"end": {
"line": 9,
"column": 41
},
"identifierName": "Array"
},
"name": "Array"
},
"property": {
"type": "Identifier",
"start": 266,
"end": 273,
"loc": {
"start": {
"line": 9,
"column": 42
},
"end": {
"line": 9,
"column": 49
},
"identifierName": "isArray"
},
"name": "isArray"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 274,
"end": 277,
"loc": {
"start": {
"line": 9,
"column": 50
},
"end": {
"line": 9,
"column": 53
},
"identifierName": "arr"
},
"name": "arr"
}
]
}
},
"consequent": {
"type": "ConditionalExpression",
"start": 290,
"end": 320,
"loc": {
"start": {
"line": 10,
"column": 10
},
"end": {
"line": 10,
"column": 40
}
},
"test": {
"type": "BinaryExpression",
"start": 290,
"end": 295,
"loc": {
"start": {
"line": 10,
"column": 10
},
"end": {
"line": 10,
"column": 15
}
},
"left": {
"type": "Identifier",
"start": 290,
"end": 291,
"loc": {
"start": {
"line": 10,
"column": 10
},
"end": {
"line": 10,
"column": 11
},
"identifierName": "n"
},
"name": "n"
},
"operator": ">",
"right": {
"type": "NumericLiteral",
"start": 294,
"end": 295,
"loc": {
"start": {
"line": 10,
"column": 14
},
"end": {
"line": 10,
"column": 15
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
},
"consequent": {
"type": "CallExpression",
"start": 298,
"end": 314,
"loc": {
"start": {
"line": 10,
"column": 18
},
"end": {
"line": 10,
"column": 34
}
},
"callee": {
"type": "Identifier",
"start": 298,
"end": 306,
"loc": {
"start": {
"line": 10,
"column": 18
},
"end": {
"line": 10,
"column": 26
},
"identifierName": "_reduser"
},
"name": "_reduser"
},
"arguments": [
{
"type": "Identifier",
"start": 307,
"end": 310,
"loc": {
"start": {
"line": 10,
"column": 27
},
"end": {
"line": 10,
"column": 30
},
"identifierName": "arr"
},
"name": "arr"
},
{
"type": "Identifier",
"start": 312,
"end": 313,
"loc": {
"start": {
"line": 10,
"column": 32
},
"end": {
"line": 10,
"column": 33
},
"identifierName": "n"
},
"name": "n"
}
]
},
"alternate": {
"type": "Identifier",
"start": 317,
"end": 320,
"loc": {
"start": {
"line": 10,
"column": 37
},
"end": {
"line": 10,
"column": 40
},
"identifierName": "arr"
},
"name": "arr"
}
},
"alternate": {
"type": "NewExpression",
"start": 332,
"end": 402,
"loc": {
"start": {
"line": 11,
"column": 10
},
"end": {
"line": 11,
"column": 80
}
},
"callee": {
"type": "Identifier",
"start": 336,
"end": 341,
"loc": {
"start": {
"line": 11,
"column": 14
},
"end": {
"line": 11,
"column": 19
},
"identifierName": "Error"
},
"name": "Error"
},
"arguments": [
{
"type": "StringLiteral",
"start": 342,
"end": 401,
"loc": {
"start": {
"line": 11,
"column": 20
},
"end": {
"line": 11,
"column": 79
}
},
"extra": {
"rawValue": "Function cast. Input must be array and factor - number.",
"raw": "'Function cast. Input must be array and factor - number.'"
},
"value": "Function cast. Input must be array and factor - number."
}
]
}
}
}
],
"directives": [],
"trailingComments": null
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Decreasing the dimension of an array by n.\r\n * @method cast\r\n * @param {any} arr - input array.\r\n * @param {number} n - decreasing factor.\r\n * @return {Array<any>|T[]|Error}\r\n ",
"start": 0,
"end": 186,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 3
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * @method _reduser\r\n * @param {Array<T>} arr - input array.\r\n * @param {number} n - decreasing factor.\r\n * @return {Array<any>}\r\n * @private\r\n ",
"start": 408,
"end": 559,
"loc": {
"start": {
"line": 13,
"column": 0
},
"end": {
"line": 19,
"column": 3
}
}
}
]
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Decreasing the dimension of an array by n.\r\n * @method cast\r\n * @param {any} arr - input array.\r\n * @param {number} n - decreasing factor.\r\n * @return {Array<any>|T[]|Error}\r\n ",
"start": 0,
"end": 186,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 3
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * @method _reduser\r\n * @param {Array<T>} arr - input array.\r\n * @param {number} n - decreasing factor.\r\n * @return {Array<any>}\r\n * @private\r\n ",
"start": 408,
"end": 559,
"loc": {
"start": {
"line": 13,
"column": 0
},
"end": {
"line": 19,
"column": 3
}
}
}
]
},
{
"type": "FunctionDeclaration",
"start": 561,
"end": 729,
"loc": {
"start": {
"line": 20,
"column": 0
},
"end": {
"line": 26,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 570,
"end": 578,
"loc": {
"start": {
"line": 20,
"column": 9
},
"end": {
"line": 20,
"column": 17
},
"identifierName": "_reduser"
},
"name": "_reduser",
"leadingComments": null
},
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 579,
"end": 582,
"loc": {
"start": {
"line": 20,
"column": 18
},
"end": {
"line": 20,
"column": 21
},
"identifierName": "arr"
},
"name": "arr"
},
{
"type": "Identifier",
"start": 584,
"end": 585,
"loc": {
"start": {
"line": 20,
"column": 23
},
"end": {
"line": 20,
"column": 24
},
"identifierName": "n"
},
"name": "n"
}
],
"body": {
"type": "BlockStatement",
"start": 587,
"end": 729,
"loc": {
"start": {
"line": 20,
"column": 26
},
"end": {
"line": 26,
"column": 1
}
},
"body": [
{
"type": "ReturnStatement",
"start": 594,
"end": 726,
"loc": {
"start": {
"line": 21,
"column": 4
},
"end": {
"line": 25,
"column": 14
}
},
"argument": {
"type": "ConditionalExpression",
"start": 601,
"end": 725,
"loc": {
"start": {
"line": 21,
"column": 11
},
"end": {
"line": 25,
"column": 13
}
},
"test": {
"type": "MemberExpression",
"start": 601,
"end": 611,
"loc": {
"start": {
"line": 21,
"column": 11
},
"end": {
"line": 21,
"column": 21
}
},
"object": {
"type": "Identifier",
"start": 601,
"end": 604,
"loc": {
"start": {
"line": 21,
"column": 11
},
"end": {
"line": 21,
"column": 14
},
"identifierName": "arr"
},
"name": "arr"
},
"property": {
"type": "Identifier",
"start": 605,
"end": 611,
"loc": {
"start": {
"line": 21,
"column": 15
},
"end": {
"line": 21,
"column": 21
},
"identifierName": "length"
},
"name": "length"
},
"computed": false
},
"consequent": {
"type": "CallExpression",
"start": 623,
"end": 710,
"loc": {
"start": {
"line": 22,
"column": 10
},
"end": {
"line": 24,
"column": 14
}
},
"callee": {
"type": "MemberExpression",
"start": 623,
"end": 633,
"loc": {
"start": {
"line": 22,
"column": 10
},
"end": {
"line": 22,
"column": 20
}
},
"object": {
"type": "Identifier",
"start": 623,
"end": 626,
"loc": {
"start": {
"line": 22,
"column": 10
},
"end": {
"line": 22,
"column": 13
},
"identifierName": "arr"
},
"name": "arr"
},
"property": {
"type": "Identifier",
"start": 627,
"end": 633,
"loc": {
"start": {
"line": 22,
"column": 14
},
"end": {
"line": 22,
"column": 20
},
"identifierName": "reduce"
},
"name": "reduce"
},
"computed": false
},
"arguments": [
{
"type": "ArrowFunctionExpression",
"start": 634,
"end": 705,
"loc": {
"start": {
"line": 22,
"column": 21
},
"end": {
"line": 24,
"column": 9
}
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 635,
"end": 638,
"loc": {
"start": {
"line": 22,
"column": 22
},
"end": {
"line": 22,
"column": 25
},
"identifierName": "acc"
},
"name": "acc"
},
{
"type": "Identifier",
"start": 640,
"end": 642,
"loc": {
"start": {
"line": 22,
"column": 27
},
"end": {
"line": 22,
"column": 29
},
"identifierName": "vL"
},
"name": "vL"
}
],
"body": {
"type": "BlockStatement",
"start": 647,
"end": 705,
"loc": {
"start": {
"line": 22,
"column": 34
},
"end": {
"line": 24,
"column": 9
}
},
"body": [
{
"type": "ReturnStatement",
"start": 662,
"end": 694,
"loc": {
"start": {
"line": 23,
"column": 12
},
"end": {
"line": 23,
"column": 44
}
},
"argument": {
"type": "CallExpression",
"start": 669,
"end": 693,
"loc": {
"start": {
"line": 23,
"column": 19
},
"end": {
"line": 23,
"column": 43
}
},
"callee": {
"type": "MemberExpression",
"start": 669,
"end": 679,
"loc": {
"start": {
"line": 23,
"column": 19
},
"end": {
"line": 23,
"column": 29
}
},
"object": {
"type": "Identifier",
"start": 669,
"end": 672,
"loc": {
"start": {
"line": 23,
"column": 19
},
"end": {
"line": 23,
"column": 22
},
"identifierName": "acc"
},
"name": "acc"
},
"property": {
"type": "Identifier",
"start": 673,
"end": 679,
"loc": {
"start": {
"line": 23,
"column": 23
},
"end": {
"line": 23,
"column": 29
},
"identifierName": "concat"
},
"name": "concat"
},
"computed": false
},
"arguments": [
{
"type": "CallExpression",
"start": 680,
"end": 692,
"loc": {
"start": {
"line": 23,
"column": 30
},
"end": {
"line": 23,
"column": 42
}
},
"callee": {
"type": "Identifier",
"start": 680,
"end": 685,
"loc": {
"start": {
"line": 23,
"column": 30
},
"end": {
"line": 23,
"column": 35
},
"identifierName": "_fact"
},
"name": "_fact"
},
"arguments": [
{
"type": "Identifier",
"start": 686,
"end": 688,
"loc": {
"start": {
"line": 23,
"column": 36
},
"end": {
"line": 23,
"column": 38
},
"identifierName": "vL"
},
"name": "vL"
},
{
"type": "Identifier",
"start": 690,
"end": 691,
"loc": {
"start": {
"line": 23,
"column": 40
},
"end": {
"line": 23,
"column": 41
},
"identifierName": "n"
},
"name": "n"
}
]
}
]
}
}
],
"directives": []
}
},
{
"type": "ArrayExpression",
"start": 707,
"end": 709,
"loc": {
"start": {
"line": 24,
"column": 11
},
"end": {
"line": 24,
"column": 13
}
},
"elements": []
}
]
},
"alternate": {
"type": "Identifier",
"start": 722,
"end": 725,
"loc": {
"start": {
"line": 25,
"column": 10
},
"end": {
"line": 25,
"column": 13
},
"identifierName": "arr"
},
"name": "arr"
}
}
}
],
"directives": [],
"trailingComments": null
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * @method _reduser\r\n * @param {Array<T>} arr - input array.\r\n * @param {number} n - decreasing factor.\r\n * @return {Array<any>}\r\n * @private\r\n ",
"start": 408,
"end": 559,
"loc": {
"start": {
"line": 13,
"column": 0
},
"end": {
"line": 19,
"column": 3
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * @method _fact\r\n * @param {Array<any>} arr - input array.\r\n * @param {number} n - decreasing factor.\r\n * @return {Array<any>}\r\n * @private\r\n ",
"start": 731,
"end": 881,
"loc": {
"start": {
"line": 27,
"column": 0
},
"end": {
"line": 33,
"column": 3
}
}
}
]
},
{
"type": "FunctionDeclaration",
"start": 883,
"end": 962,
"loc": {
"start": {
"line": 34,
"column": 0
},
"end": {
"line": 36,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 892,
"end": 897,
"loc": {
"start": {
"line": 34,
"column": 9
},
"end": {
"line": 34,
"column": 14
},
"identifierName": "_fact"
},
"name": "_fact",
"leadingComments": null
},
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 898,
"end": 901,
"loc": {
"start": {
"line": 34,
"column": 15
},
"end": {
"line": 34,
"column": 18
},
"identifierName": "arr"
},
"name": "arr"
},
{
"type": "Identifier",
"start": 903,
"end": 904,
"loc": {
"start": {
"line": 34,
"column": 20
},
"end": {
"line": 34,
"column": 21
},
"identifierName": "n"
},
"name": "n"
}
],
"body": {
"type": "BlockStatement",
"start": 906,
"end": 962,
"loc": {
"start": {
"line": 34,
"column": 23
},
"end": {
"line": 36,
"column": 1
}
},
"body": [
{
"type": "ReturnStatement",
"start": 913,
"end": 959,
"loc": {
"start": {
"line": 35,
"column": 4
},
"end": {
"line": 35,
"column": 50
}
},
"argument": {
"type": "ConditionalExpression",
"start": 920,
"end": 958,
"loc": {
"start": {
"line": 35,
"column": 11
},
"end": {
"line": 35,
"column": 49
}
},
"test": {
"type": "BinaryExpression",
"start": 921,
"end": 928,
"loc": {
"start": {
"line": 35,
"column": 12
},
"end": {
"line": 35,
"column": 19
}
},
"left": {
"type": "Identifier",
"start": 921,
"end": 922,
"loc": {
"start": {
"line": 35,
"column": 12
},
"end": {
"line": 35,
"column": 13
},
"identifierName": "n"
},
"name": "n"
},
"operator": "===",
"right": {
"type": "NumericLiteral",
"start": 927,
"end": 928,
"loc": {
"start": {
"line": 35,
"column": 18
},
"end": {
"line": 35,
"column": 19
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
},
"extra": {
"parenthesized": true,
"parenStart": 920
}
},
"consequent": {
"type": "Identifier",
"start": 932,
"end": 935,
"loc": {
"start": {
"line": 35,
"column": 23
},
"end": {
"line": 35,
"column": 26
},
"identifierName": "arr"
},
"name": "arr"
},
"alternate": {
"type": "CallExpression",
"start": 938,
"end": 958,
"loc": {
"start": {
"line": 35,
"column": 29
},
"end": {
"line": 35,
"column": 49
}
},
"callee": {
"type": "Identifier",
"start": 938,
"end": 946,
"loc": {
"start": {
"line": 35,
"column": 29
},
"end": {
"line": 35,
"column": 37
},
"identifierName": "_reduser"
},
"name": "_reduser"
},
"arguments": [
{
"type": "Identifier",
"start": 947,
"end": 950,
"loc": {
"start": {
"line": 35,
"column": 38
},
"end": {
"line": 35,
"column": 41
},
"identifierName": "arr"
},
"name": "arr"
},
{
"type": "BinaryExpression",
"start": 952,
"end": 957,
"loc": {
"start": {
"line": 35,
"column": 43
},
"end": {
"line": 35,
"column": 48
}
},
"left": {
"type": "Identifier",
"start": 952,
"end": 953,
"loc": {
"start": {
"line": 35,
"column": 43
},
"end": {
"line": 35,
"column": 44
},
"identifierName": "n"
},
"name": "n"
},
"operator": "-",
"right": {
"type": "NumericLiteral",
"start": 956,
"end": 957,
"loc": {
"start": {
"line": 35,
"column": 47
},
"end": {
"line": 35,
"column": 48
}
},
"extra": {
"rawValue": 1,
"raw": "1"
},
"value": 1
}
}
]
}
}
}
],
"directives": [],
"trailingComments": null
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * @method _fact\r\n * @param {Array<any>} arr - input array.\r\n * @param {number} n - decreasing factor.\r\n * @return {Array<any>}\r\n * @private\r\n ",
"start": 731,
"end": 881,
"loc": {
"start": {
"line": 27,
"column": 0
},
"end": {
"line": 33,
"column": 3
}
}
}
],
"trailingComments": [
{
"type": "CommentLine",
"value": "Copyright (c) 2017 Alex Tranchenko. All rights reserved.",
"start": 964,
"end": 1022,
"loc": {
"start": {
"line": 37,
"column": 0
},
"end": {
"line": 37,
"column": 58
}
}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentBlock",
"value": "*\r\n * Decreasing the dimension of an array by n.\r\n * @method cast\r\n * @param {any} arr - input array.\r\n * @param {number} n - decreasing factor.\r\n * @return {Array<any>|T[]|Error}\r\n ",
"start": 0,
"end": 186,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 7,
"column": 3
}
}
},
{
"type": "CommentBlock",
"value": "*\r\n * @method _reduser\r\n * @param {Array<T>} arr - input array.\r\n * @param {number} n - decreasing factor.\r\n * @return {Array<any>}\r\n * @private\r\n ",
"start": 408,
"end": 559,
"loc": {
"start": {
"line": 13,
"column": 0
},
"end": {
"line": 19,
"column": 3
}
}
},
{
"type": "CommentBlock",
"value": "*\r\n * @method _fact\r\n * @param {Array<any>} arr - input array.\r\n * @param {number} n - decreasing factor.\r\n * @return {Array<any>}\r\n * @private\r\n ",
"start": 731,
"end": 881,
"loc": {
"start": {