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,611 lines • 101 kB
JSON
[
{
"__docId__": 0,
"kind": "file",
"name": "src/asyncFlow.js",
"content": "import { Maybe } from \"./maybe\";\r\nimport { ErrorM } from \"./error\";\r\nimport { clone } from \"./services/clone\";\r\nimport { Monad } from \"./monad\";\r\n/**\r\n * Class AsyncFlow - for composing monads in an async flow (pipe), based on Promise.\r\n * @extends {Monad}\r\n */\r\nexport class AsyncFlow extends Monad {\r\n /**\r\n * Creates an instance of class AsyncFlow.\r\n * @param {any} [initV = 0] initV - initial value of new flow (pipe).\r\n * @param {boolean} [encapsulate = true] encapsulate - flag, if true then the init value will be cloned.\r\n */\r\n constructor(initV = 0, encapsulate = true) {\r\n super();\r\n /**\r\n * Keep initial flow (pipe) value.\r\n * @type {any}\r\n */\r\n this.flow = encapsulate ? clone(initV) : initV;\r\n /**\r\n * The instance of Maybe.\r\n * @type {Maybe}\r\n */\r\n this.maybe = new Maybe();\r\n /**\r\n * The instance of ErrorM.\r\n * @type {ErrorM}\r\n */\r\n this.err = new ErrorM();\r\n }\r\n /**\r\n * Binds initial value to the transformation function.\r\n * @method bind\r\n * @param {function(v: T) => Pr<U>} f - transformation function.\r\n * @return {Promise<T>}\r\n */\r\n bind(f) {\r\n return new Promise((resolve) => {\r\n resolve(this.err.bind(v => this.maybe.bind((v) => f(v), v), this.flow));\r\n });\r\n }\r\n}\r\n//Copyright (c) 2017 Alex Tranchenko. All rights reserved. \r\n",
"static": true,
"longname": "src/asyncFlow.js",
"access": null,
"description": null,
"lineNumber": 1
},
{
"__docId__": 1,
"kind": "class",
"name": "AsyncFlow",
"memberof": "src/asyncFlow.js",
"static": true,
"longname": "src/asyncFlow.js~AsyncFlow",
"access": null,
"export": true,
"importPath": "monad-ts/src/asyncFlow.js",
"importStyle": "{AsyncFlow}",
"description": "Class AsyncFlow - for composing monads in an async flow (pipe), based on Promise.",
"lineNumber": 9,
"interface": false,
"extends": [
"Monad"
]
},
{
"__docId__": 2,
"kind": "constructor",
"name": "constructor",
"memberof": "src/asyncFlow.js~AsyncFlow",
"generator": false,
"async": false,
"static": false,
"longname": "src/asyncFlow.js~AsyncFlow#constructor",
"access": null,
"description": "Creates an instance of class AsyncFlow.",
"lineNumber": 15,
"params": [
{
"nullable": null,
"types": [
"any"
],
"spread": false,
"optional": true,
"defaultValue": " 0",
"defaultRaw": 0,
"name": "initV",
"description": "initV - initial value of new flow (pipe)."
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": true,
"defaultValue": " true",
"defaultRaw": true,
"name": "encapsulate",
"description": "encapsulate - flag, if true then the init value will be cloned."
}
]
},
{
"__docId__": 3,
"kind": "member",
"name": "flow",
"memberof": "src/asyncFlow.js~AsyncFlow",
"static": false,
"longname": "src/asyncFlow.js~AsyncFlow#flow",
"access": null,
"description": "Keep initial flow (pipe) value.",
"lineNumber": 21,
"type": {
"nullable": null,
"types": [
"any"
],
"spread": false,
"description": null
}
},
{
"__docId__": 4,
"kind": "member",
"name": "maybe",
"memberof": "src/asyncFlow.js~AsyncFlow",
"static": false,
"longname": "src/asyncFlow.js~AsyncFlow#maybe",
"access": null,
"description": "The instance of Maybe.",
"lineNumber": 26,
"type": {
"nullable": null,
"types": [
"Maybe"
],
"spread": false,
"description": null
}
},
{
"__docId__": 5,
"kind": "member",
"name": "err",
"memberof": "src/asyncFlow.js~AsyncFlow",
"static": false,
"longname": "src/asyncFlow.js~AsyncFlow#err",
"access": null,
"description": "The instance of ErrorM.",
"lineNumber": 31,
"type": {
"nullable": null,
"types": [
"ErrorM"
],
"spread": false,
"description": null
}
},
{
"__docId__": 6,
"kind": "method",
"name": "bind",
"memberof": "src/asyncFlow.js~AsyncFlow",
"generator": false,
"async": false,
"static": false,
"longname": "src/asyncFlow.js~AsyncFlow#bind",
"access": null,
"description": "Binds initial value to the transformation function.",
"lineNumber": 39,
"unknown": [
{
"tagName": "@method",
"tagValue": "bind"
}
],
"params": [
{
"nullable": null,
"types": [
"function(v: T) => Pr<U>"
],
"spread": false,
"optional": false,
"name": "f",
"description": "transformation function."
}
],
"return": {
"nullable": null,
"types": [
"Promise<T>"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 7,
"kind": "file",
"name": "src/either.js",
"content": "import { Monad } from \"./monad\";\r\nimport { equality } from \"./services/equality\";\r\n/**\r\n * Class Either - represents computation with two possibilities.\r\n * @extends {Monad}\r\n */\r\nexport class Either extends Monad {\r\n /**\r\n * Creates an instance of class Either.\r\n * @param {function(v: any) => any} r - right function.\r\n * @param {function(v: any) => any} l - left function.\r\n */\r\n constructor(r, l) {\r\n super();\r\n this.r = r;\r\n this.l = l;\r\n }\r\n /**\r\n * Binds controller function and underlying value to the monad.\r\n * @method bind\r\n * @param {D<T>} f - controller function, after execution f(v) produce true (execute right func-n) or false (execute left func-n).\r\n * @param {any} v - underlying value for the monad.\r\n * @return {boolean | Pr<any> | Error}\r\n */\r\n bind(f, v) {\r\n this.uVal = v;\r\n try {\r\n switch (f(v)) {\r\n case true:\r\n return this.r(v);\r\n case false:\r\n return this.l(v);\r\n default:\r\n return this.fail('Either.bind() - binding error');\r\n }\r\n }\r\n catch (e) {\r\n this.fail(`Either.bind().switch - ${e}`);\r\n }\r\n }\r\n /**\r\n * Extract result of left(v) computation.\r\n * @method left\r\n * @param {T} v - underlying value.\r\n * @return {Pr}\r\n */\r\n left(v) {\r\n return this.uVal ? equality(this.uVal, v) ? this.l(v) : this.fail('Either.left() - v have been binded with bind method') : this.l(v);\r\n }\r\n /**\r\n * Extract result of right(v) computation.\r\n * @method right\r\n * @param {T} v - underlying value.\r\n * @return {Pr}\r\n */\r\n right(v) {\r\n return this.uVal ? equality(this.uVal, v) ? this.r(v) : this.fail('Either.right() - v have been binded with bind method') : this.r(v);\r\n }\r\n}\r\n//Copyright (c) 2017 Alex Tranchenko. All rights reserved. \r\n",
"static": true,
"longname": "src/either.js",
"access": null,
"description": null,
"lineNumber": 1
},
{
"__docId__": 8,
"kind": "class",
"name": "Either",
"memberof": "src/either.js",
"static": true,
"longname": "src/either.js~Either",
"access": null,
"export": true,
"importPath": "monad-ts/src/either.js",
"importStyle": "{Either}",
"description": "Class Either - represents computation with two possibilities.",
"lineNumber": 7,
"interface": false,
"extends": [
"Monad"
]
},
{
"__docId__": 9,
"kind": "constructor",
"name": "constructor",
"memberof": "src/either.js~Either",
"generator": false,
"async": false,
"static": false,
"longname": "src/either.js~Either#constructor",
"access": null,
"description": "Creates an instance of class Either.",
"lineNumber": 13,
"params": [
{
"nullable": null,
"types": [
"function(v: any) => any"
],
"spread": false,
"optional": false,
"name": "r",
"description": "right function."
},
{
"nullable": null,
"types": [
"function(v: any) => any"
],
"spread": false,
"optional": false,
"name": "l",
"description": "left function."
}
]
},
{
"__docId__": 10,
"kind": "member",
"name": "r",
"memberof": "src/either.js~Either",
"static": false,
"longname": "src/either.js~Either#r",
"access": null,
"description": null,
"lineNumber": 15,
"undocument": true,
"unknown": [
{
"tagName": "@_undocument",
"tagValue": ""
}
],
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 11,
"kind": "member",
"name": "l",
"memberof": "src/either.js~Either",
"static": false,
"longname": "src/either.js~Either#l",
"access": null,
"description": null,
"lineNumber": 16,
"undocument": true,
"unknown": [
{
"tagName": "@_undocument",
"tagValue": ""
}
],
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 12,
"kind": "method",
"name": "bind",
"memberof": "src/either.js~Either",
"generator": false,
"async": false,
"static": false,
"longname": "src/either.js~Either#bind",
"access": null,
"description": "Binds controller function and underlying value to the monad.",
"lineNumber": 25,
"unknown": [
{
"tagName": "@method",
"tagValue": "bind"
}
],
"params": [
{
"nullable": null,
"types": [
"D<T>"
],
"spread": false,
"optional": false,
"name": "f",
"description": "controller function, after execution f(v) produce true (execute right func-n) or false (execute left func-n)."
},
{
"nullable": null,
"types": [
"any"
],
"spread": false,
"optional": false,
"name": "v",
"description": "underlying value for the monad."
}
],
"return": {
"nullable": null,
"types": [
"boolean ",
" Pr<any> ",
" Error"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 13,
"kind": "member",
"name": "uVal",
"memberof": "src/either.js~Either",
"static": false,
"longname": "src/either.js~Either#uVal",
"access": null,
"description": null,
"lineNumber": 26,
"undocument": true,
"unknown": [
{
"tagName": "@_undocument",
"tagValue": ""
}
],
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 14,
"kind": "method",
"name": "left",
"memberof": "src/either.js~Either",
"generator": false,
"async": false,
"static": false,
"longname": "src/either.js~Either#left",
"access": null,
"description": "Extract result of left(v) computation.",
"lineNumber": 47,
"unknown": [
{
"tagName": "@method",
"tagValue": "left"
}
],
"params": [
{
"nullable": null,
"types": [
"T"
],
"spread": false,
"optional": false,
"name": "v",
"description": "underlying value."
}
],
"return": {
"nullable": null,
"types": [
"Pr"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 15,
"kind": "method",
"name": "right",
"memberof": "src/either.js~Either",
"generator": false,
"async": false,
"static": false,
"longname": "src/either.js~Either#right",
"access": null,
"description": "Extract result of right(v) computation.",
"lineNumber": 56,
"unknown": [
{
"tagName": "@method",
"tagValue": "right"
}
],
"params": [
{
"nullable": null,
"types": [
"T"
],
"spread": false,
"optional": false,
"name": "v",
"description": "underlying value."
}
],
"return": {
"nullable": null,
"types": [
"Pr"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 16,
"kind": "file",
"name": "src/error.js",
"content": "import { Monad } from \"./monad\";\r\n/**\r\n * Class ErrorM - return given value or produce Error if take Error or get Error after execution of f(v).\r\n * @extends {Monad}\r\n */\r\nexport class ErrorM extends Monad {\r\n /**\r\n * Chains the operations on a monadic values.\r\n * @method bind\r\n * @param {function(v: T) => Pr<U>} f - transformation function for a monad.\r\n * @param {any} v - underlying value for a monad.\r\n * @return {Pr<U> | Error} transformed by f() value v or Error.\r\n */\r\n bind(f, v) {\r\n if (v !== v || v === Infinity || v === -Infinity || v instanceof Error) {\r\n return this.fail(v);\r\n }\r\n else {\r\n const vL = this.just(f, v);\r\n return (vL !== vL || vL === Infinity || vL === -Infinity || vL instanceof Error) ? this.fail(vL) : vL;\r\n }\r\n }\r\n}\r\n//Copyright (c) 2017 Alex Tranchenko. All rights reserved. \r\n",
"static": true,
"longname": "src/error.js",
"access": null,
"description": null,
"lineNumber": 1
},
{
"__docId__": 17,
"kind": "class",
"name": "ErrorM",
"memberof": "src/error.js",
"static": true,
"longname": "src/error.js~ErrorM",
"access": null,
"export": true,
"importPath": "monad-ts/src/error.js",
"importStyle": "{ErrorM}",
"description": "Class ErrorM - return given value or produce Error if take Error or get Error after execution of f(v).",
"lineNumber": 6,
"interface": false,
"extends": [
"Monad"
]
},
{
"__docId__": 18,
"kind": "method",
"name": "bind",
"memberof": "src/error.js~ErrorM",
"generator": false,
"async": false,
"static": false,
"longname": "src/error.js~ErrorM#bind",
"access": null,
"description": "Chains the operations on a monadic values.",
"lineNumber": 14,
"unknown": [
{
"tagName": "@method",
"tagValue": "bind"
}
],
"params": [
{
"nullable": null,
"types": [
"function(v: T) => Pr<U>"
],
"spread": false,
"optional": false,
"name": "f",
"description": "transformation function for a monad."
},
{
"nullable": null,
"types": [
"any"
],
"spread": false,
"optional": false,
"name": "v",
"description": "underlying value for a monad."
}
],
"return": {
"nullable": null,
"types": [
"Pr<U> ",
" Error"
],
"spread": false,
"description": "transformed by f() value v or Error."
}
},
{
"__docId__": 19,
"kind": "file",
"name": "src/flow.js",
"content": "import { Monad } from \"./monad\";\r\nimport { Maybe } from \"./maybe\";\r\nimport { clone } from \"./services/clone\";\r\nimport { ErrorM } from \"./error\";\r\n/**\r\n * Class Flow - for composing monads in a flow (pipe).\r\n * @extends {Monad}\r\n */\r\nexport class Flow extends Monad {\r\n /**\r\n * Create an instance of class AsyncFlow.\r\n * @param {any} initV - initial value of new flow (pipe).\r\n * @param {boolean} [encapsulate = true] encapsulate - flag, if true then the init value will be cloned.\r\n */\r\n constructor(initV, encapsulate = true) {\r\n super();\r\n /**\r\n * keep initial flow (pipe) value.\r\n * @type {any}\r\n */\r\n this.flow = encapsulate ? clone(initV) : initV;\r\n /**\r\n * the instance of Maybe.\r\n * @type {Maybe}\r\n */\r\n this.maybe = new Maybe();\r\n /**\r\n * the instance of ErrorM.\r\n * @type {ErrorM}\r\n */\r\n this.err = new ErrorM();\r\n }\r\n /**\r\n * Chains the operations on a monadic values.\r\n * @method bind\r\n * @param {function(v: T) => Pr<U>} f - transformation function for a main flow value.\r\n * @param {any} [v = this.flow] - underlying value for a monad.\r\n * @return {Flow<T>} transformed by f() value v or throw Error or null.\r\n */\r\n bind(f, v = this.flow) {\r\n this.flow = this.err.bind(v => this.maybe.bind((v) => f(v), v), v);\r\n return this;\r\n }\r\n /**\r\n * Creates branch from a flow (pipe).\r\n * @method let\r\n * @param {function(v: T) => Pr<U>} f - transformation function for a main flow value.\r\n * @return {Flow<T>}\r\n */\r\n let(f) {\r\n f(clone(this.flow));\r\n return this;\r\n }\r\n /**\r\n * Extract value from a flow (pipe).\r\n * @method subscribe\r\n * @return {T}\r\n */\r\n subscribe() {\r\n return this.flow;\r\n }\r\n}\r\n//Copyright (c) 2017 Alex Tranchenko. All rights reserved.\r\n",
"static": true,
"longname": "src/flow.js",
"access": null,
"description": null,
"lineNumber": 1
},
{
"__docId__": 20,
"kind": "class",
"name": "Flow",
"memberof": "src/flow.js",
"static": true,
"longname": "src/flow.js~Flow",
"access": null,
"export": true,
"importPath": "monad-ts/src/flow.js",
"importStyle": "{Flow}",
"description": "Class Flow - for composing monads in a flow (pipe).",
"lineNumber": 9,
"interface": false,
"extends": [
"Monad"
]
},
{
"__docId__": 21,
"kind": "constructor",
"name": "constructor",
"memberof": "src/flow.js~Flow",
"generator": false,
"async": false,
"static": false,
"longname": "src/flow.js~Flow#constructor",
"access": null,
"description": "Create an instance of class AsyncFlow.",
"lineNumber": 15,
"params": [
{
"nullable": null,
"types": [
"any"
],
"spread": false,
"optional": false,
"name": "initV",
"description": "initial value of new flow (pipe)."
},
{
"nullable": null,
"types": [
"boolean"
],
"spread": false,
"optional": true,
"defaultValue": " true",
"defaultRaw": true,
"name": "encapsulate",
"description": "encapsulate - flag, if true then the init value will be cloned."
}
]
},
{
"__docId__": 22,
"kind": "member",
"name": "flow",
"memberof": "src/flow.js~Flow",
"static": false,
"longname": "src/flow.js~Flow#flow",
"access": null,
"description": "keep initial flow (pipe) value.",
"lineNumber": 21,
"type": {
"nullable": null,
"types": [
"any"
],
"spread": false,
"description": null
}
},
{
"__docId__": 23,
"kind": "member",
"name": "maybe",
"memberof": "src/flow.js~Flow",
"static": false,
"longname": "src/flow.js~Flow#maybe",
"access": null,
"description": "the instance of Maybe.",
"lineNumber": 26,
"type": {
"nullable": null,
"types": [
"Maybe"
],
"spread": false,
"description": null
}
},
{
"__docId__": 24,
"kind": "member",
"name": "err",
"memberof": "src/flow.js~Flow",
"static": false,
"longname": "src/flow.js~Flow#err",
"access": null,
"description": "the instance of ErrorM.",
"lineNumber": 31,
"type": {
"nullable": null,
"types": [
"ErrorM"
],
"spread": false,
"description": null
}
},
{
"__docId__": 25,
"kind": "method",
"name": "bind",
"memberof": "src/flow.js~Flow",
"generator": false,
"async": false,
"static": false,
"longname": "src/flow.js~Flow#bind",
"access": null,
"description": "Chains the operations on a monadic values.",
"lineNumber": 40,
"unknown": [
{
"tagName": "@method",
"tagValue": "bind"
}
],
"params": [
{
"nullable": null,
"types": [
"function(v: T) => Pr<U>"
],
"spread": false,
"optional": false,
"name": "f",
"description": "transformation function for a main flow value."
},
{
"nullable": null,
"types": [
"any"
],
"spread": false,
"optional": true,
"defaultValue": " this.flow",
"defaultRaw": " this.flow",
"name": "v",
"description": "underlying value for a monad."
}
],
"return": {
"nullable": null,
"types": [
"Flow<T>"
],
"spread": false,
"description": "transformed by f() value v or throw Error or null."
}
},
{
"__docId__": 26,
"kind": "member",
"name": "flow",
"memberof": "src/flow.js~Flow",
"static": false,
"longname": "src/flow.js~Flow#flow",
"access": null,
"description": null,
"lineNumber": 41,
"undocument": true,
"unknown": [
{
"tagName": "@_undocument",
"tagValue": ""
}
],
"type": {
"types": [
"*"
]
}
},
{
"__docId__": 27,
"kind": "method",
"name": "let",
"memberof": "src/flow.js~Flow",
"generator": false,
"async": false,
"static": false,
"longname": "src/flow.js~Flow#let",
"access": null,
"description": "Creates branch from a flow (pipe).",
"lineNumber": 50,
"unknown": [
{
"tagName": "@method",
"tagValue": "let"
}
],
"params": [
{
"nullable": null,
"types": [
"function(v: T) => Pr<U>"
],
"spread": false,
"optional": false,
"name": "f",
"description": "transformation function for a main flow value."
}
],
"return": {
"nullable": null,
"types": [
"Flow<T>"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 28,
"kind": "method",
"name": "subscribe",
"memberof": "src/flow.js~Flow",
"generator": false,
"async": false,
"static": false,
"longname": "src/flow.js~Flow#subscribe",
"access": null,
"description": "Extract value from a flow (pipe).",
"lineNumber": 59,
"unknown": [
{
"tagName": "@method",
"tagValue": "subscribe"
}
],
"params": [],
"return": {
"nullable": null,
"types": [
"T"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 29,
"kind": "file",
"name": "src/identity.js",
"content": "import { Monad } from \"./monad\";\r\nimport { clone } from \"./services/clone\";\r\nimport { equality } from \"./services/equality\";\r\nimport { ErrorM } from \"./error\";\r\n/**\r\n * Class Identity - wraps underlying value into the monadic value and compute results from a monadic value.\r\n * @extends {Monad}\r\n */\r\nexport class Identity extends Monad {\r\n /**\r\n * Creates an instance of class Identity.\r\n * @param {any} [v] - The initial state of app.\r\n * */\r\n constructor(v) {\r\n super();\r\n /**\r\n * Keeps underlying value of a monad.\r\n * @type {any}\r\n */\r\n this.v = clone(v);\r\n /**\r\n * The instance of ErrorM.\r\n * @type {ErrorM}\r\n */\r\n this.err = new ErrorM();\r\n }\r\n /**\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 */\r\n bind(f, v = this.v) {\r\n return this.v && v\r\n ? equality(this.v, v)\r\n ? f(v)\r\n : this.fail('Identity.bind() - underlying value of the monad have defined in the constructor!')\r\n : v || v === 0 || v === '' || v === null\r\n ? f(v)\r\n : f();\r\n }\r\n}\r\n//Copyright (c) 2017 Alex Tranchenko. All rights reserved.\r\n",
"static": true,
"longname": "src/identity.js",
"access": null,
"description": null,
"lineNumber": 1
},
{
"__docId__": 30,
"kind": "class",
"name": "Identity",
"memberof": "src/identity.js",
"static": true,
"longname": "src/identity.js~Identity",
"access": null,
"export": true,
"importPath": "monad-ts/src/identity.js",
"importStyle": "{Identity}",
"description": "Class Identity - wraps underlying value into the monadic value and compute results from a monadic value.",
"lineNumber": 9,
"interface": false,
"extends": [
"Monad"
]
},
{
"__docId__": 31,
"kind": "constructor",
"name": "constructor",
"memberof": "src/identity.js~Identity",
"generator": false,
"async": false,
"static": false,
"longname": "src/identity.js~Identity#constructor",
"access": null,
"description": "Creates an instance of class Identity.",
"lineNumber": 14,
"params": [
{
"nullable": null,
"types": [
"any"
],
"spread": false,
"optional": true,
"name": "v",
"description": "The initial state of app."
}
]
},
{
"__docId__": 32,
"kind": "member",
"name": "v",
"memberof": "src/identity.js~Identity",
"static": false,
"longname": "src/identity.js~Identity#v",
"access": null,
"description": "Keeps underlying value of a monad.",
"lineNumber": 20,
"type": {
"nullable": null,
"types": [
"any"
],
"spread": false,
"description": null
}
},
{
"__docId__": 33,
"kind": "member",
"name": "err",
"memberof": "src/identity.js~Identity",
"static": false,
"longname": "src/identity.js~Identity#err",
"access": null,
"description": "The instance of ErrorM.",
"lineNumber": 25,
"type": {
"nullable": null,
"types": [
"ErrorM"
],
"spread": false,
"description": null
}
},
{
"__docId__": 34,
"kind": "method",
"name": "bind",
"memberof": "src/identity.js~Identity",
"generator": false,
"async": false,
"static": false,
"longname": "src/identity.js~Identity#bind",
"access": null,
"description": "Chains the operations on a monadic value.",
"lineNumber": 34,
"unknown": [
{
"tagName": "@method",
"tagValue": "bind"
}
],
"params": [
{
"nullable": null,
"types": [
"MF<T, U>"
],
"spread": false,
"optional": false,
"name": "f",
"description": "transformation function for the monad."
},
{
"nullable": null,
"types": [
"any"
],
"spread": false,
"optional": true,
"defaultValue": " this.v",
"defaultRaw": " this.v",
"name": "v",
"description": "underlying value for the monad, it can be null."
}
],
"return": {
"nullable": null,
"types": [
"Pr<U> ",
" Error"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 35,
"kind": "file",
"name": "src/interfaces/m.js",
"content": "/**\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 */\r\nexport class M {\r\n /**\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 */\r\n just(f, v) {\r\n return void 0;\r\n }\r\n ;\r\n /**\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 */\r\n fail(e) {\r\n return void 0;\r\n }\r\n ;\r\n}\r\n//Copyright (c) 2017 Alex Tranchenko. All rights reserved. \r\n",
"static": true,
"longname": "src/interfaces/m.js",
"access": null,
"description": null,
"lineNumber": 1
},
{
"__docId__": 36,
"kind": "class",
"name": "M",
"memberof": "src/interfaces/m.js",
"static": true,
"longname": "src/interfaces/m.js~M",
"access": null,
"export": true,
"importPath": "monad-ts/src/interfaces/m.js",
"importStyle": "{M}",
"description": "interface M<T>{\n\nprotected just<T,U>(f: MF<T, U>, v: T): Pr<U>;\n\nprotected fail(e: Error | string): Error;\n\n}",
"lineNumber": 13,
"unknown": [
{
"tagName": "@noimport",
"tagValue": "true"
}
],
"interface": true
},
{
"__docId__": 37,
"kind": "method",
"name": "just",
"memberof": "src/interfaces/m.js~M",
"generator": false,
"async": false,
"static": false,
"longname": "src/interfaces/m.js~M#just",
"access": "protected",
"description": "Extracts value from monad.",
"lineNumber": 21,
"params": [
{
"nullable": null,
"types": [
"function(v: T) => Pr<U>"
],
"spread": false,
"optional": false,
"name": "f",
"description": "transformation function for a monad."
},
{
"nullable": null,
"types": [
"T"
],
"spread": false,
"optional": false,
"name": "v",
"description": "underlying value."
}
],
"return": {
"nullable": null,
"types": [
"Pr<U>"
],
"spread": false,
"description": "extracts transformed value by f(v)."
}
},
{
"__docId__": 38,
"kind": "method",
"name": "fail",
"memberof": "src/interfaces/m.js~M",
"generator": false,
"async": false,
"static": false,
"longname": "src/interfaces/m.js~M#fail",
"access": "protected",
"description": "Execute on error occur.",
"lineNumber": 31,
"params": [
{
"nullable": null,
"types": [
"Error ",
" string"
],
"spread": false,
"optional": false,
"name": "e",
"description": "Error obj. or string."
}
],
"return": {
"nullable": null,
"types": [
"Error"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 39,
"kind": "file",
"name": "src/list.js",
"content": "import { Monad } from \"./monad\";\r\n/**\r\n * Class List - transform every element of array with given function \"contemporaneously\".\r\n * @extends {Monad}\r\n */\r\nexport class List extends Monad {\r\n /**\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 */\r\n bind(f, v) {\r\n return Array.isArray(v) ? this._disp(f, v) : this.fail('List.bind() - input must be an array.');\r\n }\r\n /**\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 */\r\n _disp(f, v) {\r\n return v.map((vL) => {\r\n return !Array.isArray(vL) ? f(vL) : this._disp(f, vL);\r\n });\r\n }\r\n}\r\n//Copyright (c) 2017 Alex Tranchenko. All rights reserved.\r\n",
"static": true,
"longname": "src/list.js",
"access": null,
"description": null,
"lineNumber": 1
},
{
"__docId__": 40,
"kind": "class",
"name": "List",
"memberof": "src/list.js",
"static": true,
"longname": "src/list.js~List",
"access": null,
"export": true,
"importPath": "monad-ts/src/list.js",
"importStyle": "{List}",
"description": "Class List - transform every element of array with given function \"contemporaneously\".",
"lineNumber": 6,
"interface": false,
"extends": [
"Monad"
]
},
{
"__docId__": 41,
"kind": "method",
"name": "bind",
"memberof": "src/list.js~List",
"generator": false,
"async": false,
"static": false,
"longname": "src/list.js~List#bind",
"access": null,
"description": "Transform every element of array with given function",
"lineNumber": 14,
"unknown": [
{
"tagName": "@method",
"tagValue": "bind"
}
],
"params": [
{
"nullable": null,
"types": [
"MF<T, U>"
],
"spread": false,
"optional": false,
"name": "f",
"description": "transformation function for a monad."
},
{
"nullable": null,
"types": [
"*"
],
"spread": false,
"optional": false,
"name": "v",
"description": "underlying value for a monad."
}
],
"return": {
"nullable": null,
"types": [
"Pr<U> ",
" Error"
],
"spread": false,
"description": "transformed by f() value v or error if input arg is not array."
}
},
{
"__docId__": 42,
"kind": "method",
"name": "_disp",
"memberof": "src/list.js~List",
"generator": false,
"async": false,
"static": false,
"longname": "src/list.js~List#_disp",
"access": "private",
"description": "",
"lineNumber": 24,
"unknown": [
{
"tagName": "@method",
"tagValue": "_disp"
}
],
"params": [
{
"nullable": null,
"types": [
"function(n: T) => U"
],
"spread": false,
"optional": false,
"name": "f",
"description": "transformation function for a monad."
},
{
"nullable": null,
"types": [
"any"
],
"spread": false,
"optional": false,
"name": "v",
"description": "underlying value for a monad."
}
],
"return": {
"nullable": null,
"types": [
"Array<U>"
],
"spread": false,
"description": "transformed by f() value v."
}
},
{
"__docId__": 43,
"kind": "file",
"name": "src/maybe.js",
"content": "import { Monad } from \"./monad\";\r\n/**\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 */\r\nexport class Maybe extends Monad {\r\n /**\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 */\r\n bind(f, v) {\r\n if (v === null || v === undefined) {\r\n return this.nothing();\r\n }\r\n else {\r\n const vL = this.just(f, v);\r\n return (vL === null || vL === undefined) ? this.nothing() : vL;\r\n }\r\n }\r\n /**\r\n * Return nothing (null).\r\n * @method nothing\r\n * @return {null}\r\n */\r\n nothing() {\r\n return null;\r\n }\r\n ;\r\n}\r\n//Copyright (c) 2017 Alex Tranchenko. All rights reserved.\r\n",
"static": true,
"longname": "src/maybe.js",
"access": null,
"description": null,
"lineNumber": 1
},
{
"__docId__": 44,
"kind": "class",
"name": "Maybe",
"memberof": "src/maybe.js",
"static": true,
"longname": "src/maybe.js~Maybe",
"access": null,
"export": true,
"importPath": "monad-ts/src/maybe.js",
"importStyle": "{Maybe}",
"description": "Class Maybe - return given value or produce null if take nothing or get nothing after execution of f(v).",
"lineNumber": 6,
"interface": false,
"extends": [
"Monad"
]
},
{
"__docId__": 45,
"kind": "method",
"name": "bind",
"memberof": "src/maybe.js~Maybe",
"generator": false,
"async": false,
"static": false,
"longname": "src/maybe.js~Maybe#bind",
"access": null,
"description": "Chains the operations on a monadic values.",
"lineNumber": 14,
"unknown": [
{
"tagName": "@method",
"tagValue": "bind"
}
],
"params": [
{
"nullable": null,
"types": [
"MF<T, U>"
],
"spread": false,
"optional": false,
"name": "f",
"description": "transformation function for a monad."
},
{
"nullable": null,
"types": [
"T"
],
"spread": false,
"optional": false,
"name": "v",
"description": "underlying value for a monad."
}
],
"return": {
"nullable": null,
"types": [
"Pr<U>"
],
"spread": false,
"description": "transformed by f() value v."
}
},
{
"__docId__": 46,
"kind": "method",
"name": "nothing",
"memberof": "src/maybe.js~Maybe",
"generator": false,
"async": false,
"static": false,
"longname": "src/maybe.js~Maybe#nothing",
"access": null,
"description": "Return nothing (null).",
"lineNumber": 28,
"unknown": [
{
"tagName": "@method",
"tagValue": "nothing"
}
],
"params": [],
"return": {
"nullable": null,
"types": [
"null"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 47,
"kind": "file",
"name": "src/monad.js",
"content": "/**\r\n * Class Monad - Base abstract class.\r\n * @implements {M}\r\n * @abstract\r\n */\r\nexport class Monad {\r\n /**\r\n * Binds transformation function and underlying value to the monad.\r\n * @method bind\r\n * @param {MF<T, U> | D<T>} f - transformation function.\r\n * @param v - underlying value.\r\n * @return {Promise<U> | Pr<U> | Error | boolean | void}\r\n * @abstract\r\n */\r\n bind(f, v) {\r\n return void 0;\r\n }\r\n ;\r\n /**\r\n * Takes Error or string return Error.\r\n * @method fail\r\n * @param {Error | string} e - Error obj. or string.\r\n * @return {Error}\r\n * @protected\r\n */\r\n fail(e) {\r\n return e instanceof Error ? e : new Error(e);\r\n }\r\n /**\r\n * Produces result after execution f(v).\r\n * @method just\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 */\r\n just(f, v) {\r\n return f(v);\r\n }\r\n}\r\n//Copyright (c) 2017 Alex Tranchenko. All rights reserved.\r\n",
"static": true,
"longname": "src/monad.js",
"access": null,
"description": null,
"lineNumber": 1
},
{
"__docId__": 48,
"kind": "class",
"name": "Monad",
"memberof": "src/monad.js",
"static": true,
"longname": "src/monad.js~Monad",
"access": null,
"export": true,
"importPath": "monad-ts/src/monad.js",
"importStyle": "{Monad}",
"description": "Class Monad - Base abstract class.",
"lineNumber": 6,
"abstract": true,
"interface": false,
"implements": [
"M"
]
},
{
"__docId__": 49,
"kind": "method",
"name": "bind",
"memberof": "src/monad.js~Monad",
"generator": false,
"async": false,
"static": false,
"longname": "src/monad.js~Monad#bind",
"access": null,
"description": "Binds transformation function and underlying value to the monad.",
"lineNumber": 15,
"unknown": [
{
"tagName": "@method",
"tagValue": "bind"
}
],
"params": [
{
"nullable": null,
"types": [
"MF<T, U> | D<T>"
],
"spread": false,
"optional": false,
"name": "f",
"description": "transformation function."
},
{
"nullable": null,
"types": [
"*"
],
"spread": false,
"optional": false,
"name": "v",
"description": "underlying value."
}
],
"return": {
"nullable": null,
"types": [
"Promise<U> | Pr<U> | Error | boolean | void"
],
"spread": false,
"description": ""
},
"abstract": true
},
{
"__docId__": 50,
"kind": "method",
"name": "fail",
"memberof": "src/monad.js~Monad",
"generator": false,
"async": false,
"static": false,
"longname": "src/monad.js~Monad#fail",
"access": "protected",
"description": "Takes Error or string return Error.",
"lineNumber": 26,
"unknown": [
{
"tagName": "@method",
"tagValue": "fail"
}
],
"params": [
{
"nullable": null,
"types": [
"Error ",
" string"
],
"spread": false,
"optional": false,
"name": "e",
"description": "Error obj. or string."
}
],
"return": {
"nullable": null,
"types": [
"Error"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 51,
"kind": "method",
"name": "just",
"memberof": "src/monad.js~Monad",
"generator": false,
"async": false,
"static": false,
"longname": "src/monad.js~Monad#just",
"access": "protected",
"description": "Produces result after execution f(v).",
"lineNumber": 37,
"unknown": [
{
"tagName": "@method",
"tagValue": "just"
}
],
"params": [
{
"nullable": null,
"types": [
"function(v: T) => Pr<U>"
],
"spread": false,
"optional": false,
"name": "f",
"description": "transformation function for a monad."
},
{
"nullable": null,
"types": [
"T"
],
"spread": false,
"optional": false,
"name": "v",
"description": "underlying value."
}
],
"return": {
"nullable": null,
"types": [
"Pr<U>"
],
"spread": false,
"description": "extracts transformed value by f(v)."
}
},
{
"__docId__": 52,
"kind": "file",
"name": "src/services/cast.js",
"content": "/**\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 */\r\nexport function cast(arr, n = 0) {\r\n return typeof n === 'number' && Array.isArray(arr)\r\n ? n > 0 ? _reduser(arr, n) : arr\r\n : new Error('Function cast. Input must be array and factor - number.');\r\n}\r\n/**\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 */\r\nfunction _reduser(arr, n) {\r\n return arr.length\r\n ? arr.reduce((acc, vL) => {\r\n return acc.concat(_fact(vL, n));\r\n }, [])\r\n : arr;\r\n}\r\n/**\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 */\r\nfunction _fact(arr, n) {\r\n return (n === 1) ? arr : _reduser(arr, n - 1);\r\n}\r\n//Copyright (c) 2017 Alex Tranchenko. All rights reserved.\r\n",
"static": true,
"longname": "src/services/cast.js",
"access": null,
"description": null,
"lineNumber": 1
},
{
"__docId__": 53,
"kind": "function",
"name": "cast",
"memberof": "src/services/cast.js",
"generator": false,
"async": false,
"static": true,
"longname": "src/services/cast.js~cast",
"access": null,
"export": true,
"importPath": "monad-ts/src/services/cast.js",
"importStyle": "{cast}",
"description": "Decreasing the dimension of an array by n.",
"lineNumber": 8,
"unknown": [
{
"tagName": "@method",
"tagValue": "cast"
}
],
"params": [
{
"nullable": null,
"types": [
"any"
],
"spread": false,
"optional": false,
"name": "arr",
"description": "input array."
},
{
"nullable": null,
"types": [
"number"
],
"spread": false,
"optional": false,
"name": "n",
"description": "decreasing factor."
}
],
"return": {
"nullable": null,
"types": [
"Array<any>",
"T[]",
"Error"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 54,
"kind": "function",
"name": "_reduser",
"memberof": "src/services/cast.js",
"generator": false,
"async": false,
"static": true,
"longname": "src/services/cast.js~_reduser",
"access": "private",
"export": false,
"importPath": "monad-ts/src/services/cast.js",
"importStyle": null,
"description": "",
"lineNumber": 20,
"unknown": [
{
"tagName": "@method",
"tagValue": "_reduser"
}
],
"params": [
{
"nullable": null,
"types": [
"Array<T>"
],
"spread": false,
"optional": false,
"name": "arr",
"description": "input array."
},
{
"nullable": null,
"types": [
"number"
],
"spread": false,
"optional": false,
"name": "n",
"description": "decreasing factor."
}
],
"return": {
"nullable": null,
"types": [
"Array<any>"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 55,
"kind": "function",
"name": "_fact",
"memberof": "src/services/cast.js",
"generator": false,
"async": false,
"static": true,
"longname": "src/services/cast.js~_fact",
"access": "private",
"export": false,
"importPath": "monad-ts/src/services/cast.js",
"importStyle": null,
"description": "",
"lineNumber": 34,
"unknown": [
{
"tagName": "@method",
"tagValue": "_fact"
}
],
"params": [
{
"nullable": null,
"types": [
"Array<any>"
],
"spread": false,
"optional": false,
"name": "arr",
"description": "input array."
},
{
"nullable": null,
"types": [
"number"
],
"spread": false,
"optional": false,
"name": "n",
"description": "decreasing factor."
}
],
"return": {
"nullable": null,
"types": [
"Array<any>"
],
"spread": false,
"description": ""
}
},
{
"__docId__": 56,
"kind": "file",
"name": "src/services/clone.js",
"content": "/**\r\n * The service to clone complex objects, including Map.\r\n * @method clone\r\n * @param {T} obj - Object or Primitives to clone.\r\n * @return {T}\r\n */\r\nexport function clone(obj, map = new Map()) {\r\n // Primitives are immutable, no need to clone them.\r\n if (Object(obj) !== obj) {\r\n return obj;\r\n }\r\n else if (map.has(obj)) {\r\n // Cyclic reference handling\r\n return map.get(obj);\r\n }\r\n else {\r\n let result = Array.isArray(obj)\r\n ? []\r\n : obj.constructor && obj.constructor()\r\n ? obj.constructor()\r\n : Object.create(obj);\r\n if (Object(result) !== result) {\r\n map.set(obj, obj);\r\n result = obj;\r\n }\r\n else {\r\n map.set(obj, result);\r\n }\r\n if (obj instanceof Map) {\r\n return Array.from(obj, ([key, val]) => result.set(key, _toTail(val, map)))[0];\r\n }\r\n else {\r\n return Object.assign(result, ...Object.keys(obj).map(key => ({ [key]: _toTail(obj[key], map) })));\r\n }\r\n }\r\n}\r\n/**\r\n * @method _toTail\r\n * @param {T} obj - Object or Primitives to clone.\r\n * @param {any} map\r\n * @return {T}\r\n * @private\r\n */\r\nfunction _toTail(obj, map) {\r\n return clone(obj, map);\r\n}\r\n//Copyright (c) 2017 Alex Tranchenko. All rights reserved.\r\n",
"static": true,
"longname": "src/services/clone.js",
"access": null,
"description": null,
"lineNumber": 1
},
{
"__docId__": 57,
"kind": "function",
"name": "clone",
"memberof": "src/s