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,540 lines (1,539 loc) • 89.1 kB
JSON
{
"type": "File",
"start": 0,
"end": 947,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 34,
"column": 0
}
},
"program": {
"type": "Program",
"start": 0,
"end": 947,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 34,
"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 Maybe - return given value or produce null if take nothing or get nothing after execution of f(v).\r\n * @extends {Monad}\r\n ",
"start": 34,
"end": 172,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 5,
"column": 3
}
}
}
]
},
{
"type": "ExportNamedDeclaration",
"start": 174,
"end": 885,
"loc": {
"start": {
"line": 6,
"column": 0
},
"end": {
"line": 32,
"column": 1
}
},
"specifiers": [],
"source": null,
"declaration": {
"type": "ClassDeclaration",
"start": 181,
"end": 885,
"loc": {
"start": {
"line": 6,
"column": 7
},
"end": {
"line": 32,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 187,
"end": 192,
"loc": {
"start": {
"line": 6,
"column": 13
},
"end": {
"line": 6,
"column": 18
},
"identifierName": "Maybe"
},
"name": "Maybe",
"leadingComments": null
},
"superClass": {
"type": "Identifier",
"start": 201,
"end": 206,
"loc": {
"start": {
"line": 6,
"column": 27
},
"end": {
"line": 6,
"column": 32
},
"identifierName": "Monad"
},
"name": "Monad"
},
"body": {
"type": "ClassBody",
"start": 207,
"end": 885,
"loc": {
"start": {
"line": 6,
"column": 33
},
"end": {
"line": 32,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 476,
"end": 733,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 22,
"column": 5
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 476,
"end": 480,
"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": 481,
"end": 482,
"loc": {
"start": {
"line": 14,
"column": 9
},
"end": {
"line": 14,
"column": 10
},
"identifierName": "f"
},
"name": "f"
},
{
"type": "Identifier",
"start": 484,
"end": 485,
"loc": {
"start": {
"line": 14,
"column": 12
},
"end": {
"line": 14,
"column": 13
},
"identifierName": "v"
},
"name": "v"
}
],
"body": {
"type": "BlockStatement",
"start": 487,
"end": 733,
"loc": {
"start": {
"line": 14,
"column": 15
},
"end": {
"line": 22,
"column": 5
}
},
"body": [
{
"type": "IfStatement",
"start": 498,
"end": 726,
"loc": {
"start": {
"line": 15,
"column": 8
},
"end": {
"line": 21,
"column": 9
}
},
"test": {
"type": "LogicalExpression",
"start": 502,
"end": 531,
"loc": {
"start": {
"line": 15,
"column": 12
},
"end": {
"line": 15,
"column": 41
}
},
"left": {
"type": "BinaryExpression",
"start": 502,
"end": 512,
"loc": {
"start": {
"line": 15,
"column": 12
},
"end": {
"line": 15,
"column": 22
}
},
"left": {
"type": "Identifier",
"start": 502,
"end": 503,
"loc": {
"start": {
"line": 15,
"column": 12
},
"end": {
"line": 15,
"column": 13
},
"identifierName": "v"
},
"name": "v"
},
"operator": "===",
"right": {
"type": "NullLiteral",
"start": 508,
"end": 512,
"loc": {
"start": {
"line": 15,
"column": 18
},
"end": {
"line": 15,
"column": 22
}
}
}
},
"operator": "||",
"right": {
"type": "BinaryExpression",
"start": 516,
"end": 531,
"loc": {
"start": {
"line": 15,
"column": 26
},
"end": {
"line": 15,
"column": 41
}
},
"left": {
"type": "Identifier",
"start": 516,
"end": 517,
"loc": {
"start": {
"line": 15,
"column": 26
},
"end": {
"line": 15,
"column": 27
},
"identifierName": "v"
},
"name": "v"
},
"operator": "===",
"right": {
"type": "Identifier",
"start": 522,
"end": 531,
"loc": {
"start": {
"line": 15,
"column": 32
},
"end": {
"line": 15,
"column": 41
},
"identifierName": "undefined"
},
"name": "undefined"
}
}
},
"consequent": {
"type": "BlockStatement",
"start": 533,
"end": 581,
"loc": {
"start": {
"line": 15,
"column": 43
},
"end": {
"line": 17,
"column": 9
}
},
"body": [
{
"type": "ReturnStatement",
"start": 548,
"end": 570,
"loc": {
"start": {
"line": 16,
"column": 12
},
"end": {
"line": 16,
"column": 34
}
},
"argument": {
"type": "CallExpression",
"start": 555,
"end": 569,
"loc": {
"start": {
"line": 16,
"column": 19
},
"end": {
"line": 16,
"column": 33
}
},
"callee": {
"type": "MemberExpression",
"start": 555,
"end": 567,
"loc": {
"start": {
"line": 16,
"column": 19
},
"end": {
"line": 16,
"column": 31
}
},
"object": {
"type": "ThisExpression",
"start": 555,
"end": 559,
"loc": {
"start": {
"line": 16,
"column": 19
},
"end": {
"line": 16,
"column": 23
}
}
},
"property": {
"type": "Identifier",
"start": 560,
"end": 567,
"loc": {
"start": {
"line": 16,
"column": 24
},
"end": {
"line": 16,
"column": 31
},
"identifierName": "nothing"
},
"name": "nothing"
},
"computed": false
},
"arguments": []
}
}
],
"directives": []
},
"alternate": {
"type": "BlockStatement",
"start": 596,
"end": 726,
"loc": {
"start": {
"line": 18,
"column": 13
},
"end": {
"line": 21,
"column": 9
}
},
"body": [
{
"type": "VariableDeclaration",
"start": 611,
"end": 638,
"loc": {
"start": {
"line": 19,
"column": 12
},
"end": {
"line": 19,
"column": 39
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 617,
"end": 637,
"loc": {
"start": {
"line": 19,
"column": 18
},
"end": {
"line": 19,
"column": 38
}
},
"id": {
"type": "Identifier",
"start": 617,
"end": 619,
"loc": {
"start": {
"line": 19,
"column": 18
},
"end": {
"line": 19,
"column": 20
},
"identifierName": "vL"
},
"name": "vL"
},
"init": {
"type": "CallExpression",
"start": 622,
"end": 637,
"loc": {
"start": {
"line": 19,
"column": 23
},
"end": {
"line": 19,
"column": 38
}
},
"callee": {
"type": "MemberExpression",
"start": 622,
"end": 631,
"loc": {
"start": {
"line": 19,
"column": 23
},
"end": {
"line": 19,
"column": 32
}
},
"object": {
"type": "ThisExpression",
"start": 622,
"end": 626,
"loc": {
"start": {
"line": 19,
"column": 23
},
"end": {
"line": 19,
"column": 27
}
}
},
"property": {
"type": "Identifier",
"start": 627,
"end": 631,
"loc": {
"start": {
"line": 19,
"column": 28
},
"end": {
"line": 19,
"column": 32
},
"identifierName": "just"
},
"name": "just"
},
"computed": false
},
"arguments": [
{
"type": "Identifier",
"start": 632,
"end": 633,
"loc": {
"start": {
"line": 19,
"column": 33
},
"end": {
"line": 19,
"column": 34
},
"identifierName": "f"
},
"name": "f"
},
{
"type": "Identifier",
"start": 635,
"end": 636,
"loc": {
"start": {
"line": 19,
"column": 36
},
"end": {
"line": 19,
"column": 37
},
"identifierName": "v"
},
"name": "v"
}
]
}
}
],
"kind": "const"
},
{
"type": "ReturnStatement",
"start": 652,
"end": 715,
"loc": {
"start": {
"line": 20,
"column": 12
},
"end": {
"line": 20,
"column": 75
}
},
"argument": {
"type": "ConditionalExpression",
"start": 659,
"end": 714,
"loc": {
"start": {
"line": 20,
"column": 19
},
"end": {
"line": 20,
"column": 74
}
},
"test": {
"type": "LogicalExpression",
"start": 660,
"end": 691,
"loc": {
"start": {
"line": 20,
"column": 20
},
"end": {
"line": 20,
"column": 51
}
},
"left": {
"type": "BinaryExpression",
"start": 660,
"end": 671,
"loc": {
"start": {
"line": 20,
"column": 20
},
"end": {
"line": 20,
"column": 31
}
},
"left": {
"type": "Identifier",
"start": 660,
"end": 662,
"loc": {
"start": {
"line": 20,
"column": 20
},
"end": {
"line": 20,
"column": 22
},
"identifierName": "vL"
},
"name": "vL"
},
"operator": "===",
"right": {
"type": "NullLiteral",
"start": 667,
"end": 671,
"loc": {
"start": {
"line": 20,
"column": 27
},
"end": {
"line": 20,
"column": 31
}
}
}
},
"operator": "||",
"right": {
"type": "BinaryExpression",
"start": 675,
"end": 691,
"loc": {
"start": {
"line": 20,
"column": 35
},
"end": {
"line": 20,
"column": 51
}
},
"left": {
"type": "Identifier",
"start": 675,
"end": 677,
"loc": {
"start": {
"line": 20,
"column": 35
},
"end": {
"line": 20,
"column": 37
},
"identifierName": "vL"
},
"name": "vL"
},
"operator": "===",
"right": {
"type": "Identifier",
"start": 682,
"end": 691,
"loc": {
"start": {
"line": 20,
"column": 42
},
"end": {
"line": 20,
"column": 51
},
"identifierName": "undefined"
},
"name": "undefined"
}
},
"extra": {
"parenthesized": true,
"parenStart": 659
}
},
"consequent": {
"type": "CallExpression",
"start": 695,
"end": 709,
"loc": {
"start": {
"line": 20,
"column": 55
},
"end": {
"line": 20,
"column": 69
}
},
"callee": {
"type": "MemberExpression",
"start": 695,
"end": 707,
"loc": {
"start": {
"line": 20,
"column": 55
},
"end": {
"line": 20,
"column": 67
}
},
"object": {
"type": "ThisExpression",
"start": 695,
"end": 699,
"loc": {
"start": {
"line": 20,
"column": 55
},
"end": {
"line": 20,
"column": 59
}
}
},
"property": {
"type": "Identifier",
"start": 700,
"end": 707,
"loc": {
"start": {
"line": 20,
"column": 60
},
"end": {
"line": 20,
"column": 67
},
"identifierName": "nothing"
},
"name": "nothing"
},
"computed": false
},
"arguments": []
},
"alternate": {
"type": "Identifier",
"start": 712,
"end": 714,
"loc": {
"start": {
"line": 20,
"column": 72
},
"end": {
"line": 20,
"column": 74
},
"identifierName": "vL"
},
"name": "vL"
}
}
}
],
"directives": []
}
}
],
"directives": [],
"trailingComments": null
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Chains the operations on a monadic values.\r\n * @method bind\r\n * @param {MF<T, U>} f - transformation function for a monad.\r\n * @param {T} v - underlying value for a monad.\r\n * @return {Pr<U>} transformed by f() value v.\r\n ",
"start": 214,
"end": 470,
"loc": {
"start": {
"line": 7,
"column": 4
},
"end": {
"line": 13,
"column": 7
}
}
}
],
"trailingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Return nothing (null).\r\n * @method nothing\r\n * @return {null}\r\n ",
"start": 739,
"end": 829,
"loc": {
"start": {
"line": 23,
"column": 4
},
"end": {
"line": 27,
"column": 7
}
}
}
]
},
{
"type": "ClassMethod",
"start": 835,
"end": 875,
"loc": {
"start": {
"line": 28,
"column": 4
},
"end": {
"line": 30,
"column": 5
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 835,
"end": 842,
"loc": {
"start": {
"line": 28,
"column": 4
},
"end": {
"line": 28,
"column": 11
},
"identifierName": "nothing"
},
"name": "nothing",
"leadingComments": null
},
"static": false,
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start": 845,
"end": 875,
"loc": {
"start": {
"line": 28,
"column": 14
},
"end": {
"line": 30,
"column": 5
}
},
"body": [
{
"type": "ReturnStatement",
"start": 856,
"end": 868,
"loc": {
"start": {
"line": 29,
"column": 8
},
"end": {
"line": 29,
"column": 20
}
},
"argument": {
"type": "NullLiteral",
"start": 863,
"end": 867,
"loc": {
"start": {
"line": 29,
"column": 15
},
"end": {
"line": 29,
"column": 19
}
}
}
}
],
"directives": []
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Return nothing (null).\r\n * @method nothing\r\n * @return {null}\r\n ",
"start": 739,
"end": 829,
"loc": {
"start": {
"line": 23,
"column": 4
},
"end": {
"line": 27,
"column": 7
}
}
}
]
}
],
"trailingComments": null
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Class Maybe - return given value or produce null if take nothing or get nothing after execution of f(v).\r\n * @extends {Monad}\r\n ",
"start": 34,
"end": 172,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 5,
"column": 3
}
}
}
],
"trailingComments": [
{
"type": "CommentLine",
"value": "Copyright (c) 2017 Alex Tranchenko. All rights reserved.",
"start": 887,
"end": 945,
"loc": {
"start": {
"line": 33,
"column": 0
},
"end": {
"line": 33,
"column": 58
}
}
}
]
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Class Maybe - return given value or produce null if take nothing or get nothing after execution of f(v).\r\n * @extends {Monad}\r\n ",
"start": 34,
"end": 172,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 5,
"column": 3
}
}
}
],
"trailingComments": [
{
"type": "CommentLine",
"value": "Copyright (c) 2017 Alex Tranchenko. All rights reserved.",
"start": 887,
"end": 945,
"loc": {
"start": {
"line": 33,
"column": 0
},
"end": {
"line": 33,
"column": 58
}
}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentBlock",
"value": "*\r\n * Class Maybe - return given value or produce null if take nothing or get nothing after execution of f(v).\r\n * @extends {Monad}\r\n ",
"start": 34,
"end": 172,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 5,
"column": 3
}
}
},
{
"type": "CommentBlock",
"value": "*\r\n * Chains the operations on a monadic values.\r\n * @method bind\r\n * @param {MF<T, U>} f - transformation function for a monad.\r\n * @param {T} v - underlying value for a monad.\r\n * @return {Pr<U>} transformed by f() value v.\r\n ",
"start": 214,
"end": 470,
"loc": {
"start": {
"line": 7,
"column": 4
},
"end": {
"line": 13,
"column": 7
}
}
},
{
"type": "CommentBlock",
"value": "*\r\n * Return nothing (null).\r\n * @method nothing\r\n * @return {null}\r\n ",
"start": 739,
"end": 829,
"loc": {
"start": {
"line": 23,
"column": 4
},
"end": {
"line": 27,
"column": 7
}
}
},
{
"type": "CommentLine",
"value": "Copyright (c) 2017 Alex Tranchenko. All rights reserved.",
"start": 887,
"end": 945,
"loc": {
"start": {
"line": 33,
"column": 0
},
"end": {
"line": 33,
"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": "{",
"beforeExpr": true,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 7,
"end": 8,
"loc": {
"start": {
"line": 1,
"column": 7
},
"end": {
"line": 1,
"column": 8
}
}
},
{
"type": {
"label": "name",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"value": "Monad",
"start": 9,
"end": 14,
"loc": {
"start": {
"line": 1,
"column": 9
},
"end": {
"line": 1,
"column": 14
}
}
},
{
"type": {
"label": "}",
"beforeExpr": false,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 15,
"end": 16,
"loc": {
"start": {
"line": 1,
"column": 15
},
"end": {
"line": 1,
"column": 16
}
}
},
{
"type": {
"label": "name",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"value": "from",
"start": 17,
"end": 21,
"loc": {
"start": {
"line": 1,
"column": 17
},
"end": {
"line": 1,
"column": 21
}
}
},
{
"type": {
"label": "string",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"value": "./monad",
"start": 22,
"end": 31,
"loc": {
"start": {
"line": 1,
"column": 22
},
"end": {
"line": 1,
"column": 31
}
}
},
{
"type": {
"label": ";",
"beforeExpr": true,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"start": 31,
"end": 32,
"loc": {
"start": {
"line": 1,
"column": 31
},
"end": {
"line": 1,
"column": 32
}
}
},
{
"type": "CommentBlock",
"value": "*\r\n * Class Maybe - return given value or produce null if take nothing or get nothing after execution of f(v).\r\n * @extends {Monad}\r\n ",
"start": 34,
"end": 172,
"loc": {
"start": {
"line": 2,
"column": 0
},
"end": {
"line": 5,
"column": 3
}
}
},
{
"type": {
"label": "export",
"keyword": "export",
"beforeExpr": false,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"value": "export",
"start": 174,
"end": 180,
"loc": {
"start": {
"line": 6,
"column": 0
},
"end": {
"line": 6,
"column": 6
}
}
},
{
"type": {
"label": "class",
"keyword": "class",
"beforeExpr": false,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"value": "class",
"start": 181,
"end": 186,
"loc": {
"start": {
"line": 6,
"column": 7
},
"end": {
"line": 6,
"column": 12
}
}
},
{
"type": {
"label": "name",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"value": "Maybe",
"start": 187,
"end": 192,
"loc": {
"start": {
"line": 6,
"column": 13
},
"end": {
"line": 6,
"column": 18
}
}
},
{
"type": {
"label": "extends",
"keyword": "extends",
"beforeExpr": true,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"value": "extends",
"start": 193,
"end": 200,
"loc": {
"start": {
"line": 6,
"column": 19
},
"end": {
"line": 6,
"column": 26
}
}
},
{
"type": {
"label": "name",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,