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,356 lines • 97.7 kB
JSON
{
"type": "File",
"start": 0,
"end": 1080,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 31,
"column": 0
}
},
"program": {
"type": "Program",
"start": 0,
"end": 1080,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 31,
"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"
},
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Class List - transform every element of array with given function \"contemporaneously\".\r\n * @extends {Monad}\r\n ",
"start": 34,
"end": 154,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 5,
"column": 3
}
}
}
]
},
{
"type": "ExportNamedDeclaration",
"start": 156,
"end": 1018,
"loc": {
"start": {
"line": 6,
"column": 0
},
"end": {
"line": 29,
"column": 1
}
},
"specifiers": [],
"source": null,
"declaration": {
"type": "ClassDeclaration",
"start": 163,
"end": 1018,
"loc": {
"start": {
"line": 6,
"column": 7
},
"end": {
"line": 29,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 169,
"end": 173,
"loc": {
"start": {
"line": 6,
"column": 13
},
"end": {
"line": 6,
"column": 17
},
"identifierName": "List"
},
"name": "List",
"leadingComments": null
},
"superClass": {
"type": "Identifier",
"start": 182,
"end": 187,
"loc": {
"start": {
"line": 6,
"column": 26
},
"end": {
"line": 6,
"column": 31
},
"identifierName": "Monad"
},
"name": "Monad"
},
"body": {
"type": "ClassBody",
"start": 188,
"end": 1018,
"loc": {
"start": {
"line": 6,
"column": 32
},
"end": {
"line": 29,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 506,
"end": 631,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 16,
"column": 5
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 506,
"end": 510,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 14,
"column": 8
},
"identifierName": "bind"
},
"name": "bind",
"leadingComments": null
},
"static": false,
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 511,
"end": 512,
"loc": {
"start": {
"line": 14,
"column": 9
},
"end": {
"line": 14,
"column": 10
},
"identifierName": "f"
},
"name": "f"
},
{
"type": "Identifier",
"start": 514,
"end": 515,
"loc": {
"start": {
"line": 14,
"column": 12
},
"end": {
"line": 14,
"column": 13
},
"identifierName": "v"
},
"name": "v"
}
],
"body": {
"type": "BlockStatement",
"start": 517,
"end": 631,
"loc": {
"start": {
"line": 14,
"column": 15
},
"end": {
"line": 16,
"column": 5
}
},
"body": [
{
"type": "ReturnStatement",
"start": 528,
"end": 624,
"loc": {
"start": {
"line": 15,
"column": 8
},
"end": {
"line": 15,
"column": 104
}
},
"argument": {
"type": "ConditionalExpression",
"start": 535,
"end": 623,
"loc": {
"start": {
"line": 15,
"column": 15
},
"end": {
"line": 15,
"column": 103
}
},
"test": {
"type": "CallExpression",
"start": 535,
"end": 551,
"loc": {
"start": {
"line": 15,
"column": 15
},
"end": {
"line": 15,
"column": 31
}
},
"callee": {
"type": "MemberExpression",
"start": 535,
"end": 548,
"loc": {
"start": {
"line": 15,
"column": 15
},
"end": {
"line": 15,
"column": 28
}
},
"object": {
"type": "Identifier",
"start": 535,
"end": 540,
"loc": {
"start": {
"line": 15,
"column": 15
},
"end": {
"line": 15,
"column": 20
},
"identifierName": "Array"
},
"name": "Array"
},
"property": {
"type": "Identifier",
"start": 541,
"end": 548,
"loc": {
"start": {
"line": 15,
"column": 21
},
"end": {
"line": 15,
"column": 28
},
"identifierName": "isArray"
},
"name": "isArray"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 549,
"end": 550,
"loc": {
"start": {
"line": 15,
"column": 29
},
"end": {
"line": 15,
"column": 30
},
"identifierName": "v"
},
"name": "v"
}
]
},
"consequent": {
"type": "CallExpression",
"start": 554,
"end": 570,
"loc": {
"start": {
"line": 15,
"column": 34
},
"end": {
"line": 15,
"column": 50
}
},
"callee": {
"type": "MemberExpression",
"start": 554,
"end": 564,
"loc": {
"start": {
"line": 15,
"column": 34
},
"end": {
"line": 15,
"column": 44
}
},
"object": {
"type": "ThisExpression",
"start": 554,
"end": 558,
"loc": {
"start": {
"line": 15,
"column": 34
},
"end": {
"line": 15,
"column": 38
}
}
},
"property": {
"type": "Identifier",
"start": 559,
"end": 564,
"loc": {
"start": {
"line": 15,
"column": 39
},
"end": {
"line": 15,
"column": 44
},
"identifierName": "_disp"
},
"name": "_disp"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 565,
"end": 566,
"loc": {
"start": {
"line": 15,
"column": 45
},
"end": {
"line": 15,
"column": 46
},
"identifierName": "f"
},
"name": "f"
},
{
"type": "Identifier",
"start": 568,
"end": 569,
"loc": {
"start": {
"line": 15,
"column": 48
},
"end": {
"line": 15,
"column": 49
},
"identifierName": "v"
},
"name": "v"
}
]
},
"alternate": {
"type": "CallExpression",
"start": 573,
"end": 623,
"loc": {
"start": {
"line": 15,
"column": 53
},
"end": {
"line": 15,
"column": 103
}
},
"callee": {
"type": "MemberExpression",
"start": 573,
"end": 582,
"loc": {
"start": {
"line": 15,
"column": 53
},
"end": {
"line": 15,
"column": 62
}
},
"object": {
"type": "ThisExpression",
"start": 573,
"end": 577,
"loc": {
"start": {
"line": 15,
"column": 53
},
"end": {
"line": 15,
"column": 57
}
}
},
"property": {
"type": "Identifier",
"start": 578,
"end": 582,
"loc": {
"start": {
"line": 15,
"column": 58
},
"end": {
"line": 15,
"column": 62
},
"identifierName": "fail"
},
"name": "fail"
},
"computed": false
},
"arguments": [
{
"type": "StringLiteral",
"start": 583,
"end": 622,
"loc": {
"start": {
"line": 15,
"column": 63
},
"end": {
"line": 15,
"column": 102
}
},
"extra": {
"rawValue": "List.bind() - input must be an array.",
"raw": "'List.bind() - input must be an array.'"
},
"value": "List.bind() - input must be an array."
}
]
}
}
}
],
"directives": [],
"trailingComments": null
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Transform every element of array with given function\r\n * @method bind\r\n * @param {MF<T, U>} f - transformation function for a monad.\r\n * @param v - underlying value for a monad.\r\n * @return {Pr<U> | Error} transformed by f() value v or error if input arg is not array.\r\n ",
"start": 195,
"end": 500,
"loc": {
"start": {
"line": 7,
"column": 4
},
"end": {
"line": 13,
"column": 7
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * @method _disp\r\n * @param {function(n: T) => U} f - transformation function for a monad.\r\n * @param {any} v - underlying value for a monad.\r\n * @return {Array<U>} transformed by f() value v.\r\n * @private\r\n ",
"start": 637,
"end": 876,
"loc": {
"start": {
"line": 17,
"column": 4
},
"end": {
"line": 23,
"column": 7
}
}
}
]
},
{
"type": "ClassMethod",
"start": 882,
"end": 1015,
"loc": {
"start": {
"line": 24,
"column": 4
},
"end": {
"line": 28,
"column": 5
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 882,
"end": 887,
"loc": {
"start": {
"line": 24,
"column": 4
},
"end": {
"line": 24,
"column": 9
},
"identifierName": "_disp"
},
"name": "_disp",
"leadingComments": null
},
"static": false,
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 888,
"end": 889,
"loc": {
"start": {
"line": 24,
"column": 10
},
"end": {
"line": 24,
"column": 11
},
"identifierName": "f"
},
"name": "f"
},
{
"type": "Identifier",
"start": 891,
"end": 892,
"loc": {
"start": {
"line": 24,
"column": 13
},
"end": {
"line": 24,
"column": 14
},
"identifierName": "v"
},
"name": "v"
}
],
"body": {
"type": "BlockStatement",
"start": 894,
"end": 1015,
"loc": {
"start": {
"line": 24,
"column": 16
},
"end": {
"line": 28,
"column": 5
}
},
"body": [
{
"type": "ReturnStatement",
"start": 905,
"end": 1008,
"loc": {
"start": {
"line": 25,
"column": 8
},
"end": {
"line": 27,
"column": 11
}
},
"argument": {
"type": "CallExpression",
"start": 912,
"end": 1007,
"loc": {
"start": {
"line": 25,
"column": 15
},
"end": {
"line": 27,
"column": 10
}
},
"callee": {
"type": "MemberExpression",
"start": 912,
"end": 917,
"loc": {
"start": {
"line": 25,
"column": 15
},
"end": {
"line": 25,
"column": 20
}
},
"object": {
"type": "Identifier",
"start": 912,
"end": 913,
"loc": {
"start": {
"line": 25,
"column": 15
},
"end": {
"line": 25,
"column": 16
},
"identifierName": "v"
},
"name": "v"
},
"property": {
"type": "Identifier",
"start": 914,
"end": 917,
"loc": {
"start": {
"line": 25,
"column": 17
},
"end": {
"line": 25,
"column": 20
},
"identifierName": "map"
},
"name": "map"
},
"computed": false
},
"arguments": [
{
"type": "ArrowFunctionExpression",
"start": 918,
"end": 1006,
"loc": {
"start": {
"line": 25,
"column": 21
},
"end": {
"line": 27,
"column": 9
}
},
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 919,
"end": 921,
"loc": {
"start": {
"line": 25,
"column": 22
},
"end": {
"line": 25,
"column": 24
},
"identifierName": "vL"
},
"name": "vL"
}
],
"body": {
"type": "BlockStatement",
"start": 926,
"end": 1006,
"loc": {
"start": {
"line": 25,
"column": 29
},
"end": {
"line": 27,
"column": 9
}
},
"body": [
{
"type": "ReturnStatement",
"start": 941,
"end": 995,
"loc": {
"start": {
"line": 26,
"column": 12
},
"end": {
"line": 26,
"column": 66
}
},
"argument": {
"type": "ConditionalExpression",
"start": 948,
"end": 994,
"loc": {
"start": {
"line": 26,
"column": 19
},
"end": {
"line": 26,
"column": 65
}
},
"test": {
"type": "UnaryExpression",
"start": 948,
"end": 966,
"loc": {
"start": {
"line": 26,
"column": 19
},
"end": {
"line": 26,
"column": 37
}
},
"operator": "!",
"prefix": true,
"argument": {
"type": "CallExpression",
"start": 949,
"end": 966,
"loc": {
"start": {
"line": 26,
"column": 20
},
"end": {
"line": 26,
"column": 37
}
},
"callee": {
"type": "MemberExpression",
"start": 949,
"end": 962,
"loc": {
"start": {
"line": 26,
"column": 20
},
"end": {
"line": 26,
"column": 33
}
},
"object": {
"type": "Identifier",
"start": 949,
"end": 954,
"loc": {
"start": {
"line": 26,
"column": 20
},
"end": {
"line": 26,
"column": 25
},
"identifierName": "Array"
},
"name": "Array"
},
"property": {
"type": "Identifier",
"start": 955,
"end": 962,
"loc": {
"start": {
"line": 26,
"column": 26
},
"end": {
"line": 26,
"column": 33
},
"identifierName": "isArray"
},
"name": "isArray"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 963,
"end": 965,
"loc": {
"start": {
"line": 26,
"column": 34
},
"end": {
"line": 26,
"column": 36
},
"identifierName": "vL"
},
"name": "vL"
}
]
},
"extra": {
"parenthesizedArgument": false
}
},
"consequent": {
"type": "CallExpression",
"start": 969,
"end": 974,
"loc": {
"start": {
"line": 26,
"column": 40
},
"end": {
"line": 26,
"column": 45
}
},
"callee": {
"type": "Identifier",
"start": 969,
"end": 970,
"loc": {
"start": {
"line": 26,
"column": 40
},
"end": {
"line": 26,
"column": 41
},
"identifierName": "f"
},
"name": "f"
},
"arguments": [
{
"type": "Identifier",
"start": 971,
"end": 973,
"loc": {
"start": {
"line": 26,
"column": 42
},
"end": {
"line": 26,
"column": 44
},
"identifierName": "vL"
},
"name": "vL"
}
]
},
"alternate": {
"type": "CallExpression",
"start": 977,
"end": 994,
"loc": {
"start": {
"line": 26,
"column": 48
},
"end": {
"line": 26,
"column": 65
}
},
"callee": {
"type": "MemberExpression",
"start": 977,
"end": 987,
"loc": {
"start": {
"line": 26,
"column": 48
},
"end": {
"line": 26,
"column": 58
}
},
"object": {
"type": "ThisExpression",
"start": 977,
"end": 981,
"loc": {
"start": {
"line": 26,
"column": 48
},
"end": {
"line": 26,
"column": 52
}
}
},
"property": {
"type": "Identifier",
"start": 982,
"end": 987,
"loc": {
"start": {
"line": 26,
"column": 53
},
"end": {
"line": 26,
"column": 58
},
"identifierName": "_disp"
},
"name": "_disp"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 988,
"end": 989,
"loc": {
"start": {
"line": 26,
"column": 59
},
"end": {
"line": 26,
"column": 60
},
"identifierName": "f"
},
"name": "f"
},
{
"type": "Identifier",
"start": 991,
"end": 993,
"loc": {
"start": {
"line": 26,
"column": 62
},
"end": {
"line": 26,
"column": 64
},
"identifierName": "vL"
},
"name": "vL"
}
]
}
}
}
],
"directives": []
}
}
]
}
}
],
"directives": []
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * @method _disp\r\n * @param {function(n: T) => U} f - transformation function for a monad.\r\n * @param {any} v - underlying value for a monad.\r\n * @return {Array<U>} transformed by f() value v.\r\n * @private\r\n ",
"start": 637,
"end": 876,
"loc": {
"start": {
"line": 17,
"column": 4
},
"end": {
"line": 23,
"column": 7
}
}
}
]
}
],
"trailingComments": null
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Class List - transform every element of array with given function \"contemporaneously\".\r\n * @extends {Monad}\r\n ",
"start": 34,
"end": 154,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 5,
"column": 3
}
}
}
],
"trailingComments": [
{
"type": "CommentLine",
"value": "Copyright (c) 2017 Alex Tranchenko. All rights reserved.",
"start": 1020,
"end": 1078,
"loc": {
"start": {
"line": 30,
"column": 0
},
"end": {
"line": 30,
"column": 58
}
}
}
]
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Class List - transform every element of array with given function \"contemporaneously\".\r\n * @extends {Monad}\r\n ",
"start": 34,
"end": 154,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 5,
"column": 3
}
}
}
],
"trailingComments": [
{
"type": "CommentLine",
"value": "Copyright (c) 2017 Alex Tranchenko. All rights reserved.",
"start": 1020,
"end": 1078,
"loc": {
"start": {
"line": 30,
"column": 0
},
"end": {
"line": 30,
"column": 58
}
}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentBlock",
"value": "*\r\n * Class List - transform every element of array with given function \"contemporaneously\".\r\n * @extends {Monad}\r\n ",
"start": 34,
"end": 154,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 5,
"column": 3
}
}
},
{
"type": "CommentBlock",
"value": "*\r\n * Transform every element of array with given function\r\n * @method bind\r\n * @param {MF<T, U>} f - transformation function for a monad.\r\n * @param v - underlying value for a monad.\r\n * @return {Pr<U> | Error} transformed by f() value v or error if input arg is not array.\r\n ",
"start": 195,
"end": 500,
"loc": {
"start": {
"line": 7,
"column": 4
},
"end": {
"line": 13,
"column": 7
}
}
},
{
"type": "CommentBlock",
"value": "*\r\n * @method _disp\r\n * @param {function(n: T) => U} f - transformation function for a monad.\r\n * @param {any} v - underlying value for a monad.\r\n * @return {Array<U>} transformed by f() value v.\r\n * @private\r\n ",
"start": 637,
"end": 876,
"loc": {
"start": {
"line": 17,
"column": 4
},
"end": {
"line": 23,
"column": 7
}
}
},
{
"type": "CommentLine",
"value": "Copyright (c) 2017 Alex Tranchenko. All rights reserved.",
"start": 1020,
"end": 1078,
"loc": {
"start": {
"line": 30,
"column": 0
},
"end": {
"line": 30,
"column": 58
}
}
}
],
"tokens": [
{
"type": {
"label": "import",
"keyword": "import",
"beforeExpr": false,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"value": "import",
"start": 0,
"end": 6,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 1,
"column": 6
}
}
},
{
"type": {
"label": "{",
"beforeEx