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,408 lines • 34 kB
JSON
{
"type": "File",
"start": 0,
"end": 824,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 37,
"column": 0
}
},
"program": {
"type": "Program",
"start": 0,
"end": 824,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 37,
"column": 0
}
},
"sourceType": "module",
"body": [
{
"type": "ExportNamedDeclaration",
"start": 227,
"end": 761,
"loc": {
"start": {
"line": 13,
"column": 0
},
"end": {
"line": 35,
"column": 1
}
},
"specifiers": [],
"source": null,
"declaration": {
"type": "ClassDeclaration",
"start": 234,
"end": 761,
"loc": {
"start": {
"line": 13,
"column": 7
},
"end": {
"line": 35,
"column": 1
}
},
"id": {
"type": "Identifier",
"start": 240,
"end": 241,
"loc": {
"start": {
"line": 13,
"column": 13
},
"end": {
"line": 13,
"column": 14
},
"identifierName": "M"
},
"name": "M",
"leadingComments": null
},
"superClass": null,
"body": {
"type": "ClassBody",
"start": 242,
"end": 761,
"loc": {
"start": {
"line": 13,
"column": 15
},
"end": {
"line": 35,
"column": 1
}
},
"body": [
{
"type": "ClassMethod",
"start": 504,
"end": 547,
"loc": {
"start": {
"line": 21,
"column": 4
},
"end": {
"line": 23,
"column": 5
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 504,
"end": 508,
"loc": {
"start": {
"line": 21,
"column": 4
},
"end": {
"line": 21,
"column": 8
},
"identifierName": "just"
},
"name": "just",
"leadingComments": null
},
"static": false,
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 509,
"end": 510,
"loc": {
"start": {
"line": 21,
"column": 9
},
"end": {
"line": 21,
"column": 10
},
"identifierName": "f"
},
"name": "f"
},
{
"type": "Identifier",
"start": 512,
"end": 513,
"loc": {
"start": {
"line": 21,
"column": 12
},
"end": {
"line": 21,
"column": 13
},
"identifierName": "v"
},
"name": "v"
}
],
"body": {
"type": "BlockStatement",
"start": 515,
"end": 547,
"loc": {
"start": {
"line": 21,
"column": 15
},
"end": {
"line": 23,
"column": 5
}
},
"body": [
{
"type": "ReturnStatement",
"start": 526,
"end": 540,
"loc": {
"start": {
"line": 22,
"column": 8
},
"end": {
"line": 22,
"column": 22
}
},
"argument": {
"type": "UnaryExpression",
"start": 533,
"end": 539,
"loc": {
"start": {
"line": 22,
"column": 15
},
"end": {
"line": 22,
"column": 21
}
},
"operator": "void",
"prefix": true,
"argument": {
"type": "NumericLiteral",
"start": 538,
"end": 539,
"loc": {
"start": {
"line": 22,
"column": 20
},
"end": {
"line": 22,
"column": 21
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
},
"extra": {
"parenthesizedArgument": false
}
}
}
],
"directives": []
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Extracts value from monad.\r\n * @param {function(v: T) => Pr<U>} f - transformation function for a monad.\r\n * @param {T} v - underlying value.\r\n * @return {Pr<U>} extracts transformed value by f(v).\r\n * @protected\r\n ",
"start": 249,
"end": 498,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 20,
"column": 7
}
}
}
]
},
{
"type": "ClassMethod",
"start": 711,
"end": 751,
"loc": {
"start": {
"line": 31,
"column": 4
},
"end": {
"line": 33,
"column": 5
}
},
"computed": false,
"key": {
"type": "Identifier",
"start": 711,
"end": 715,
"loc": {
"start": {
"line": 31,
"column": 4
},
"end": {
"line": 31,
"column": 8
},
"identifierName": "fail"
},
"name": "fail",
"leadingComments": null
},
"static": false,
"kind": "method",
"id": null,
"generator": false,
"expression": false,
"async": false,
"params": [
{
"type": "Identifier",
"start": 716,
"end": 717,
"loc": {
"start": {
"line": 31,
"column": 9
},
"end": {
"line": 31,
"column": 10
},
"identifierName": "e"
},
"name": "e"
}
],
"body": {
"type": "BlockStatement",
"start": 719,
"end": 751,
"loc": {
"start": {
"line": 31,
"column": 12
},
"end": {
"line": 33,
"column": 5
}
},
"body": [
{
"type": "ReturnStatement",
"start": 730,
"end": 744,
"loc": {
"start": {
"line": 32,
"column": 8
},
"end": {
"line": 32,
"column": 22
}
},
"argument": {
"type": "UnaryExpression",
"start": 737,
"end": 743,
"loc": {
"start": {
"line": 32,
"column": 15
},
"end": {
"line": 32,
"column": 21
}
},
"operator": "void",
"prefix": true,
"argument": {
"type": "NumericLiteral",
"start": 742,
"end": 743,
"loc": {
"start": {
"line": 32,
"column": 20
},
"end": {
"line": 32,
"column": 21
}
},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
},
"extra": {
"parenthesizedArgument": false
}
}
}
],
"directives": []
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * Execute on error occur.\r\n * @param {Error | string} e - Error obj. or string.\r\n * @return {Error}\r\n * @protected\r\n ",
"start": 560,
"end": 705,
"loc": {
"start": {
"line": 25,
"column": 4
},
"end": {
"line": 30,
"column": 7
}
}
}
]
}
],
"trailingComments": null
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * interface M<T>{\r\n *\r\n * protected just<T,U>(f: MF<T, U>, v: T): Pr<U>;\r\n *\r\n * protected fail(e: Error | string): Error;\r\n *\r\n * }\r\n * @interface\r\n * @name M - monads interface, {@link Monad}.\r\n * @noimport true\r\n ",
"start": 0,
"end": 225,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 12,
"column": 3
}
}
}
],
"trailingComments": [
{
"type": "CommentLine",
"value": "Copyright (c) 2017 Alex Tranchenko. All rights reserved. ",
"start": 763,
"end": 822,
"loc": {
"start": {
"line": 36,
"column": 0
},
"end": {
"line": 36,
"column": 59
}
}
}
]
},
"leadingComments": [
{
"type": "CommentBlock",
"value": "*\r\n * interface M<T>{\r\n *\r\n * protected just<T,U>(f: MF<T, U>, v: T): Pr<U>;\r\n *\r\n * protected fail(e: Error | string): Error;\r\n *\r\n * }\r\n * @interface\r\n * @name M - monads interface, {@link Monad}.\r\n * @noimport true\r\n ",
"start": 0,
"end": 225,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 12,
"column": 3
}
}
}
],
"trailingComments": [
{
"type": "CommentLine",
"value": "Copyright (c) 2017 Alex Tranchenko. All rights reserved. ",
"start": 763,
"end": 822,
"loc": {
"start": {
"line": 36,
"column": 0
},
"end": {
"line": 36,
"column": 59
}
}
}
]
}
],
"directives": []
},
"comments": [
{
"type": "CommentBlock",
"value": "*\r\n * interface M<T>{\r\n *\r\n * protected just<T,U>(f: MF<T, U>, v: T): Pr<U>;\r\n *\r\n * protected fail(e: Error | string): Error;\r\n *\r\n * }\r\n * @interface\r\n * @name M - monads interface, {@link Monad}.\r\n * @noimport true\r\n ",
"start": 0,
"end": 225,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 12,
"column": 3
}
}
},
{
"type": "CommentBlock",
"value": "*\r\n * Extracts value from monad.\r\n * @param {function(v: T) => Pr<U>} f - transformation function for a monad.\r\n * @param {T} v - underlying value.\r\n * @return {Pr<U>} extracts transformed value by f(v).\r\n * @protected\r\n ",
"start": 249,
"end": 498,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 20,
"column": 7
}
}
},
{
"type": "CommentBlock",
"value": "*\r\n * Execute on error occur.\r\n * @param {Error | string} e - Error obj. or string.\r\n * @return {Error}\r\n * @protected\r\n ",
"start": 560,
"end": 705,
"loc": {
"start": {
"line": 25,
"column": 4
},
"end": {
"line": 30,
"column": 7
}
}
},
{
"type": "CommentLine",
"value": "Copyright (c) 2017 Alex Tranchenko. All rights reserved. ",
"start": 763,
"end": 822,
"loc": {
"start": {
"line": 36,
"column": 0
},
"end": {
"line": 36,
"column": 59
}
}
}
],
"tokens": [
{
"type": "CommentBlock",
"value": "*\r\n * interface M<T>{\r\n *\r\n * protected just<T,U>(f: MF<T, U>, v: T): Pr<U>;\r\n *\r\n * protected fail(e: Error | string): Error;\r\n *\r\n * }\r\n * @interface\r\n * @name M - monads interface, {@link Monad}.\r\n * @noimport true\r\n ",
"start": 0,
"end": 225,
"loc": {
"start": {
"line": 1,
"column": 0
},
"end": {
"line": 12,
"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": 227,
"end": 233,
"loc": {
"start": {
"line": 13,
"column": 0
},
"end": {
"line": 13,
"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": 234,
"end": 239,
"loc": {
"start": {
"line": 13,
"column": 7
},
"end": {
"line": 13,
"column": 12
}
}
},
{
"type": {
"label": "name",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"value": "M",
"start": 240,
"end": 241,
"loc": {
"start": {
"line": 13,
"column": 13
},
"end": {
"line": 13,
"column": 14
}
}
},
{
"type": {
"label": "{",
"beforeExpr": true,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 242,
"end": 243,
"loc": {
"start": {
"line": 13,
"column": 15
},
"end": {
"line": 13,
"column": 16
}
}
},
{
"type": "CommentBlock",
"value": "*\r\n * Extracts value from monad.\r\n * @param {function(v: T) => Pr<U>} f - transformation function for a monad.\r\n * @param {T} v - underlying value.\r\n * @return {Pr<U>} extracts transformed value by f(v).\r\n * @protected\r\n ",
"start": 249,
"end": 498,
"loc": {
"start": {
"line": 14,
"column": 4
},
"end": {
"line": 20,
"column": 7
}
}
},
{
"type": {
"label": "name",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"value": "just",
"start": 504,
"end": 508,
"loc": {
"start": {
"line": 21,
"column": 4
},
"end": {
"line": 21,
"column": 8
}
}
},
{
"type": {
"label": "(",
"beforeExpr": true,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 508,
"end": 509,
"loc": {
"start": {
"line": 21,
"column": 8
},
"end": {
"line": 21,
"column": 9
}
}
},
{
"type": {
"label": "name",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"value": "f",
"start": 509,
"end": 510,
"loc": {
"start": {
"line": 21,
"column": 9
},
"end": {
"line": 21,
"column": 10
}
}
},
{
"type": {
"label": ",",
"beforeExpr": true,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"start": 510,
"end": 511,
"loc": {
"start": {
"line": 21,
"column": 10
},
"end": {
"line": 21,
"column": 11
}
}
},
{
"type": {
"label": "name",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"value": "v",
"start": 512,
"end": 513,
"loc": {
"start": {
"line": 21,
"column": 12
},
"end": {
"line": 21,
"column": 13
}
}
},
{
"type": {
"label": ")",
"beforeExpr": false,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 513,
"end": 514,
"loc": {
"start": {
"line": 21,
"column": 13
},
"end": {
"line": 21,
"column": 14
}
}
},
{
"type": {
"label": "{",
"beforeExpr": true,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 515,
"end": 516,
"loc": {
"start": {
"line": 21,
"column": 15
},
"end": {
"line": 21,
"column": 16
}
}
},
{
"type": {
"label": "return",
"keyword": "return",
"beforeExpr": true,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"value": "return",
"start": 526,
"end": 532,
"loc": {
"start": {
"line": 22,
"column": 8
},
"end": {
"line": 22,
"column": 14
}
}
},
{
"type": {
"label": "void",
"keyword": "void",
"beforeExpr": true,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": true,
"postfix": false,
"binop": null,
"updateContext": null
},
"value": "void",
"start": 533,
"end": 537,
"loc": {
"start": {
"line": 22,
"column": 15
},
"end": {
"line": 22,
"column": 19
}
}
},
{
"type": {
"label": "num",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"value": 0,
"start": 538,
"end": 539,
"loc": {
"start": {
"line": 22,
"column": 20
},
"end": {
"line": 22,
"column": 21
}
}
},
{
"type": {
"label": ";",
"beforeExpr": true,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"start": 539,
"end": 540,
"loc": {
"start": {
"line": 22,
"column": 21
},
"end": {
"line": 22,
"column": 22
}
}
},
{
"type": {
"label": "}",
"beforeExpr": false,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 546,
"end": 547,
"loc": {
"start": {
"line": 23,
"column": 4
},
"end": {
"line": 23,
"column": 5
}
}
},
{
"type": {
"label": ";",
"beforeExpr": true,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"start": 553,
"end": 554,
"loc": {
"start": {
"line": 24,
"column": 4
},
"end": {
"line": 24,
"column": 5
}
}
},
{
"type": "CommentBlock",
"value": "*\r\n * Execute on error occur.\r\n * @param {Error | string} e - Error obj. or string.\r\n * @return {Error}\r\n * @protected\r\n ",
"start": 560,
"end": 705,
"loc": {
"start": {
"line": 25,
"column": 4
},
"end": {
"line": 30,
"column": 7
}
}
},
{
"type": {
"label": "name",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"value": "fail",
"start": 711,
"end": 715,
"loc": {
"start": {
"line": 31,
"column": 4
},
"end": {
"line": 31,
"column": 8
}
}
},
{
"type": {
"label": "(",
"beforeExpr": true,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 715,
"end": 716,
"loc": {
"start": {
"line": 31,
"column": 8
},
"end": {
"line": 31,
"column": 9
}
}
},
{
"type": {
"label": "name",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"value": "e",
"start": 716,
"end": 717,
"loc": {
"start": {
"line": 31,
"column": 9
},
"end": {
"line": 31,
"column": 10
}
}
},
{
"type": {
"label": ")",
"beforeExpr": false,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 717,
"end": 718,
"loc": {
"start": {
"line": 31,
"column": 10
},
"end": {
"line": 31,
"column": 11
}
}
},
{
"type": {
"label": "{",
"beforeExpr": true,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 719,
"end": 720,
"loc": {
"start": {
"line": 31,
"column": 12
},
"end": {
"line": 31,
"column": 13
}
}
},
{
"type": {
"label": "return",
"keyword": "return",
"beforeExpr": true,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"value": "return",
"start": 730,
"end": 736,
"loc": {
"start": {
"line": 32,
"column": 8
},
"end": {
"line": 32,
"column": 14
}
}
},
{
"type": {
"label": "void",
"keyword": "void",
"beforeExpr": true,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": true,
"postfix": false,
"binop": null,
"updateContext": null
},
"value": "void",
"start": 737,
"end": 741,
"loc": {
"start": {
"line": 32,
"column": 15
},
"end": {
"line": 32,
"column": 19
}
}
},
{
"type": {
"label": "num",
"beforeExpr": false,
"startsExpr": true,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"value": 0,
"start": 742,
"end": 743,
"loc": {
"start": {
"line": 32,
"column": 20
},
"end": {
"line": 32,
"column": 21
}
}
},
{
"type": {
"label": ";",
"beforeExpr": true,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"start": 743,
"end": 744,
"loc": {
"start": {
"line": 32,
"column": 21
},
"end": {
"line": 32,
"column": 22
}
}
},
{
"type": {
"label": "}",
"beforeExpr": false,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 750,
"end": 751,
"loc": {
"start": {
"line": 33,
"column": 4
},
"end": {
"line": 33,
"column": 5
}
}
},
{
"type": {
"label": ";",
"beforeExpr": true,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"start": 757,
"end": 758,
"loc": {
"start": {
"line": 34,
"column": 4
},
"end": {
"line": 34,
"column": 5
}
}
},
{
"type": {
"label": "}",
"beforeExpr": false,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null
},
"start": 760,
"end": 761,
"loc": {
"start": {
"line": 35,
"column": 0
},
"end": {
"line": 35,
"column": 1
}
}
},
{
"type": "CommentLine",
"value": "Copyright (c) 2017 Alex Tranchenko. All rights reserved. ",
"start": 763,
"end": 822,
"loc": {
"start": {
"line": 36,
"column": 0
},
"end": {
"line": 36,
"column": 59
}
}
},
{
"type": {
"label": "eof",
"beforeExpr": false,
"startsExpr": false,
"rightAssociative": false,
"isLoop": false,
"isAssign": false,
"prefix": false,
"postfix": false,
"binop": null,
"updateContext": null
},
"start": 824,
"end": 824,
"loc": {
"start": {
"line": 37,
"column": 0
},
"end": {
"line": 37,
"column": 0
}
}
}
]
}