{"_id":"@dudousxd/monad.ts","_rev":"4-6a4319d2621519ba2189f73b8b4eee5d","name":"@dudousxd/monad.ts","dist-tags":{"latest":"1.0.3"},"versions":{"1.0.0":{"name":"@dudousxd/monad.ts","version":"1.0.0","main":"src/index.js","license":"MIT","repository":{"type":"git","url":"git+https://github.com/DavideCarvalho/monad.ts.git"},"bugs":{"url":"https://github.com/DavideCarvalho/monad.ts/issues"},"author":{"name":"Davi de Carvalho","email":"davi_carvalho96@hotmail.com","url":"https://github.com/DavideCarvalho"},"scripts":{"test":"nyc node_modules/.bin/mocha","test:coverage":"nyc node_modules/.bin/mocha && node_modules/.bin/nyc report --reporter=text","build":"tsc"},"devDependencies":{"@types/chai":"^4.1.2","@types/mocha":"^5.0.0","chai":"^4.1.2","jest":"^22.4.3","mocha":"^5.0.5","nyc":"^11.6.0","source-map-support":"^0.5.4","ts-jest":"^22.4.2","ts-node":"^5.0.1","typescript":"^2.8.1","typings":"^2.1.1"},"nyc":{"extension":[".ts",".tsx"],"exclude":["**/*.d.ts","coverage/**","**/*.test.ts","**/dist/*.js"],"reporter":["html"],"all":true},"gitHead":"682f8b06e818348bcfac8ab5978589e4b737aac2","description":"> Monad Structure for TypeScript","homepage":"https://github.com/DavideCarvalho/monad.ts#readme","_id":"@dudousxd/monad.ts@1.0.0","_npmVersion":"5.8.0","_nodeVersion":"8.9.3","_npmUser":{"name":"dudousxd","email":"davi_carvalho96@hotmail.com"},"dist":{"integrity":"sha512-gpfWdiwi382Rz1aHQiodXOLBaJlf5RA9Ytax2Vyljln6veN/t/l02uN6rKwRTRdqSv37zGto0LUURcHbDI3SwA==","shasum":"d66faafef29ce98fd826c1fa2cfb063846cbd37f","tarball":"https://registry.npmjs.org/@dudousxd/monad.ts/-/monad.ts-1.0.0.tgz","fileCount":20,"unpackedSize":362946,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa1fABCRA9TVsSAnZWagAAX+sQAKRdrU4VhFIkkrkhwMgF\nH4tHk20LWIehtBIwn51cWiX7Ae+/fSwWkDIJQipH6yRM3ZSurGABi51un+CM\n2LpvxV+MrMWOlyKAB6iJPXfJs9rAX1TGPswQIcKCMHtrCvwF7bS71cinbPOm\n4YUvsE3TSf5eVX1o4bCtTptMwbZ3ozWBYEfZlAzIJyy7bbj7IuDc2ovhN8QQ\nbGHtZsj6OHah6aD7kcv85bnlII5d+SGPDxYxVeKn2bJkCttGs1IcKhRD25nE\n7PoqKI8XUk1MoB8iBI6HA5y3n2b4VFFsARZUEGG0VRqZWBXvFa4dVAWwN+rq\n48eApc/+3U5iyjq2JxbhWKVPXy+Y3+zipKfRsZgk4hYS6gdr42ixlMuPifBo\nxkBCEDVXCL7k7aEOTWT0SUcoB+whaxpgzL/Hw7owbqagbAEMLaQ4+vBdtt4s\n8VT+mN4Tk6rgl2ma88+IHc/Ro2u+Eoh2+9SSJ2+Hpb3cNRybIktuwkvQCPCi\nYUGRWw6LUOgKdsjBeZdcnnPfPDt7JeJteuu2BvYccnnwyCd6CI2VXebOR/V1\n/KcSvUO2h7YF0v5ifcMbjfRcnO8hoIC3Wen/jOvrUwGMFsQt+jXr5f/O2hOz\nbvOQMhZH2kGm7FvPQ9SGDPT7zZ/tpWfLX76AHz5IeAy3QtsHEDpArhF2lYLY\nkwBx\r\n=Y3pP\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBqzEbxSukuuDP0LLV0LIf8DpHHwuo/wawrAriwHJhzFAiEAiY0iXBqnHXyskP4irylPROcT8UqnYfUuZFPasBmig9k="}]},"maintainers":[{"name":"dudousxd","email":"davi_carvalho96@hotmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/monad.ts_1.0.0_1523970048300_0.07157338694689352"},"_hasShrinkwrap":false},"1.0.1":{"name":"@dudousxd/monad.ts","version":"1.0.1","main":"src/index.js","license":"MIT","repository":{"type":"git","url":"git+https://github.com/DavideCarvalho/monad.ts.git"},"bugs":{"url":"https://github.com/DavideCarvalho/monad.ts/issues"},"author":{"name":"Davi de Carvalho","email":"davi_carvalho96@hotmail.com","url":"https://github.com/DavideCarvalho"},"scripts":{"test":"nyc node_modules/.bin/mocha","test:coverage":"nyc node_modules/.bin/mocha && node_modules/.bin/nyc report --reporter=text","build":"tsc"},"devDependencies":{"@types/chai":"^4.1.2","@types/mocha":"^5.0.0","chai":"^4.1.2","jest":"^22.4.3","mocha":"^5.0.5","nyc":"^11.6.0","source-map-support":"^0.5.4","ts-jest":"^22.4.2","ts-node":"^5.0.1","typescript":"^2.8.1","typings":"^2.1.1"},"nyc":{"extension":[".ts",".tsx"],"exclude":["**/*.d.ts","coverage/**","**/*.test.ts","**/dist/*.js"],"reporter":["html"],"all":true},"gitHead":"756180a384615759f41128932294872a5834caf3","description":"> Monad Structure for TypeScript","homepage":"https://github.com/DavideCarvalho/monad.ts#readme","_id":"@dudousxd/monad.ts@1.0.1","_npmVersion":"5.8.0","_nodeVersion":"8.9.3","_npmUser":{"name":"dudousxd","email":"davi_carvalho96@hotmail.com"},"dist":{"integrity":"sha512-t4I7Q00pj8xMA7s1k6cSdjbV8qVHQOjx0fxGgLpNxpyeoRyS0zhLiskTai8tPSern814+p3qYlei7kV+/sHpQQ==","shasum":"21e530fc589f92bb136c6332c27f3f4c24d14761","tarball":"https://registry.npmjs.org/@dudousxd/monad.ts/-/monad.ts-1.0.1.tgz","fileCount":20,"unpackedSize":363051,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa1fLsCRA9TVsSAnZWagAAyq0QAJ5EKze8K1q/vqhGAko9\nBQ6zdJJ7MbRoCt2w7j2CpuJ4ag7jt6glcfSzoQik7PYzidjI5rFLhijoCHJV\nmfZoeDFlo4hvF7M4hoVkoWQiILIq7b4kjwyXMi8BryMO/e1IyJ17Zu5nnrHe\n9Zex/2M8pjkzMEB+tzDbB01vUdfS4MzIT6qDsacdee/ZCKzBL2cabyHoeAXh\nANuP4efWunuVPsKr2RzguZ0tGg+91jyFfv46488HqPjKdeTDMpONkSLBkl5x\nGh4UiFUGHAP6UeYlgOo9iCtFKDpGXqD8wTyREuUNRxSxgS8lTvrpbLXSJgJF\nYf7CpS24CqUO8R0pUCQ9N+vLPG5gWhKdpzQ9YoVhFWfudlm0B41BfyT5cUNE\nWYwqc3EMMQWY1MR+GZnAITMkBugGK/wa3nx6usBsYvYh6fcOfd1vK1rTbJXW\nlYiD8yCWTwgC5Uox8WBfCeYWaEQZtoxLqT38/Ss0FnWtKaoXdMD3gcZbD3RG\nf9P8x4kRBsmAjS0BSOskMcZ3Z0L2YN6FJFeWpdF5CO+a4LmOlNgO8u9tW7D2\niY5FT+nYvKng+q6RLHZR2+qJo8iekdz7kEbsNdyFiyiAG7Gy2qzRj0HZBsqO\nt2od/oxrjbWqCokq/dzFdLAZrXbXcsvHFH9V75MhIerq63ykpgls9AEqMPxF\nJh0q\r\n=0V08\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICqpLmcSvtCxXK0rUdeYwsCczCs0O86oJKndwOb++3SDAiBUL2sP1DqQrXYL3RSCcWYx5CW8CJmkwL4GPGZjO1wLAA=="}]},"maintainers":[{"name":"dudousxd","email":"davi_carvalho96@hotmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/monad.ts_1.0.1_1523970796102_0.7475959288690857"},"_hasShrinkwrap":false},"1.0.2":{"name":"@dudousxd/monad.ts","version":"1.0.2","main":"src/index.js","license":"MIT","repository":{"type":"git","url":"git+https://github.com/DavideCarvalho/monad.ts.git"},"bugs":{"url":"https://github.com/DavideCarvalho/monad.ts/issues"},"author":{"name":"Davi de Carvalho","email":"davi_carvalho96@hotmail.com","url":"https://github.com/DavideCarvalho"},"scripts":{"test":"nyc node_modules/.bin/mocha","test:coverage":"nyc node_modules/.bin/mocha && node_modules/.bin/nyc report --reporter=text","build":"tsc"},"devDependencies":{"@types/chai":"^4.1.2","@types/mocha":"^5.0.0","chai":"^4.1.2","jest":"^22.4.3","mocha":"^5.0.5","nyc":"^11.6.0","source-map-support":"^0.5.4","ts-jest":"^22.4.2","ts-node":"^5.0.1","typescript":"^2.8.1","typings":"^2.1.1"},"nyc":{"extension":[".ts",".tsx"],"exclude":["**/*.d.ts","coverage/**","**/*.test.ts","**/dist/*.js"],"reporter":["html"],"all":true},"gitHead":"dab44ca86f8d0568fe2da3f3ba8ac46697ee0698","description":"<p>\r     <a href=\"https://www.npmjs.com/package/graphql-simple-request\"><img src=\"https://img.shields.io/npm/v/@dudousxd/monad.ts.svg?maxAge=3600\" alt=\"NPM version\" /></a>\r     <a href=\"https://www.npmjs.com/package/graphql-simple-request\"><img src=\"https","homepage":"https://github.com/DavideCarvalho/monad.ts#readme","_id":"@dudousxd/monad.ts@1.0.2","_npmVersion":"5.8.0","_nodeVersion":"8.9.3","_npmUser":{"name":"dudousxd","email":"davi_carvalho96@hotmail.com"},"dist":{"integrity":"sha512-A2LV4DNp0yno4/K+QUF2v+p7/rkNFu7BoTAGAOvoxvtXj01Zqpn6tQf7u/+40Dr+F26KO6/csaEUVOOW3lc6LQ==","shasum":"95c9af6f9e13d33fe6a83c6e069a91b74a30e3ca","tarball":"https://registry.npmjs.org/@dudousxd/monad.ts/-/monad.ts-1.0.2.tgz","fileCount":20,"unpackedSize":363403,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa1fPVCRA9TVsSAnZWagAAlBEP/3XQXcm29joaJoppfP7M\nuWBzpUSmBvKF8hj0i32yG2uVp058jW+BcLDhHXn0f3VJCYcuzvpPfHunV6OS\niB/xHEIIKOtq1oYI9xQmkjcYcY6N7sCwh1I8DauclIBVSS/GRGprq+1Lu04q\nrDTZt07e2lRxodz3hnalw76DMp9Vt2noaYIEEQcFExJnU/tLGaIrbx6Yhn1X\npoSqABOYds9OFskZPoybHDli/5wFWEikawK5nr4BzJxqkp/JrJTpRqqbmdGD\nlZYvMtzqAy8ebYk4h1jsaQL49y3OtfEDNc7jf9h7fWkNlkFqXqR22FpCmCAa\ntPj2st+VXqdQjruJ0+mI2z+GFCq7CS2RLvzRgdZ1BrvU3dh96zNasX2kF9hZ\nN3VVUnqP5NB2L1Oia6etpry/qjPmlZZuFAa04lZiSd4cAs/ljZmKLtKEyO6b\n4ubZBLNFGdR61uiTuSr9LqWjIme3YtBsBWaKSlr4sl+GGBStT6ek0PzBLeUt\nvhXbcsVaSj+cPTRngRkQZOTt5oBd0LGRbIl0VUL+uDl7CbPpF2sdYy8stIdq\n8ChfOgRyfLzCaKbEma43835io4cjthcFwMF8O+Aj0fFrq33ZIVI15V4UBp8m\nLUyLcgYJIBPGkTxoaJdiqKq3ymrRpU+8gvGrIa9VoVJHOjcr3LH7mF/eEGij\nSR71\r\n=yst+\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIB7q1ZqA8hFR57E8zGzYu0575z7y50hdvsZ0J/2iYEUFAiBmk8DL7HfILHuapf2sRZpdk9sHtsLg96TPxrMlcOXlFw=="}]},"maintainers":[{"name":"dudousxd","email":"davi_carvalho96@hotmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/monad.ts_1.0.2_1523971029265_0.7219561960480585"},"_hasShrinkwrap":false},"1.0.3":{"name":"@dudousxd/monad.ts","version":"1.0.3","main":"src/index.js","license":"MIT","repository":{"type":"git","url":"git+https://github.com/DavideCarvalho/monad.ts.git"},"bugs":{"url":"https://github.com/DavideCarvalho/monad.ts/issues"},"author":{"name":"Davi de Carvalho","email":"davi_carvalho96@hotmail.com","url":"https://github.com/DavideCarvalho"},"scripts":{"test":"nyc node_modules/.bin/mocha","test:coverage":"nyc node_modules/.bin/mocha && node_modules/.bin/nyc report --reporter=text","build":"tsc"},"devDependencies":{"@types/chai":"^4.1.2","@types/mocha":"^5.0.0","chai":"^4.1.2","jest":"^22.4.3","mocha":"^5.0.5","nyc":"^11.6.0","source-map-support":"^0.5.4","ts-jest":"^22.4.2","ts-node":"^5.0.1","typescript":"^2.8.1","typings":"^2.1.1"},"nyc":{"extension":[".ts",".tsx"],"exclude":["**/*.d.ts","coverage/**","**/*.test.ts","**/dist/*.js"],"reporter":["html"],"all":true},"gitHead":"078b056e014663e0fa35ce7f7d6b3cc81465ae18","description":"<p>\r     <a href=\"https://www.npmjs.com/package/@dudousxd/monad.ts\"><img src=\"https://img.shields.io/npm/v/@dudousxd/monad.ts.svg?maxAge=3600\" alt=\"NPM version\" /></a>\r     <a href=\"https://www.npmjs.com/package/@dudousxd/monad.ts\"><img src=\"https://img.s","homepage":"https://github.com/DavideCarvalho/monad.ts#readme","_id":"@dudousxd/monad.ts@1.0.3","_npmVersion":"5.8.0","_nodeVersion":"8.9.3","_npmUser":{"name":"dudousxd","email":"davi_carvalho96@hotmail.com"},"dist":{"integrity":"sha512-t8n7V6bsTyeIEtpC/uwWfZKfbidmGpB1aRFjFmhD/DTCJDjkXJjD+1qbUDmy5Qw1RhXT9R8cCHBGmsSnsOhAEw==","shasum":"ec14487b9959939447618ecc6b051e54163391be","tarball":"https://registry.npmjs.org/@dudousxd/monad.ts/-/monad.ts-1.0.3.tgz","fileCount":20,"unpackedSize":363395,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa1fSzCRA9TVsSAnZWagAAm84P/3dCAqQaclMcZ9VFCgwz\nUjhlQi+8hrG7L3Ej3o2BpuSFVfJC594nN9CZKUqe6aGi7zRxzXdHha6V9+od\noVd9LsmSw7g9Rizgsz39JbTi4HesXOrEFye+F6EY3pW7615jD8SksrOXL7s9\n1rzcpzOJAsfXfxgWJzZ5D0vbe5sDTL/QwjKoJ03YJRRlQZfy6otVVA9NPRU1\nXAFba7zM32Gu6iy+1B4KKwscUBTft5HW6/MeH4WPkwmImDpWq6oO7Fj8Wstk\nwOaO8YmmK1nYGZcVz+4nRw50UJNGHBmNKrG2HLzWPufhAPpalOVYo62R+mE8\n7ZC6HtrjkJ9FLQeOWwWDvXRj0+cieEhjqmTti6tqz0aP3PkyNOG/lC9Jxgkf\ngk0R9mBC1dwLJrGkSrow/XiJ7OBOpv35hQTfgfsDKPqput3/FKrCzt2TPG3i\nwynrT4ZzFLZvUPZckIDR18LuNYALPQTqg2NCAWlAhxn7ccelpALQ7z53bVqN\npYSyAj5SPuEqgrhDQY45T5JsE9+iRFJFkoM+CMPGSc4RTJHomibdUyVZyj5A\njDeDz0aMmOVKJs9EfABWXFio+8hpK0WTcnoKsMFWcCzKY2+N6fPogvnPqNwo\n4NJrWBXPBy2UhawiA+cYYWMki95Ga3V7dAl+8RylfgXIGZ40Uu7eTpccwimk\n4hDE\r\n=z+0z\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCID6MiBZVwikrJnGSTh3PXiqtWsQnADrac5D0Xo4LttSXAiBzK2CrXRgJrjZKTzWL0BM+uBoa7F36jsLW/5Lovjqbcg=="}]},"maintainers":[{"name":"dudousxd","email":"davi_carvalho96@hotmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/monad.ts_1.0.3_1523971250636_0.055265223343587966"},"_hasShrinkwrap":false}},"time":{"created":"2018-04-17T13:00:48.242Z","1.0.0":"2018-04-17T13:00:48.453Z","modified":"2022-04-05T06:07:04.713Z","1.0.1":"2018-04-17T13:13:16.247Z","1.0.2":"2018-04-17T13:17:09.319Z","1.0.3":"2018-04-17T13:20:50.731Z"},"maintainers":[{"name":"dudousxd","email":"davi_carvalho96@hotmail.com"}],"description":"<p>\r     <a href=\"https://www.npmjs.com/package/@dudousxd/monad.ts\"><img src=\"https://img.shields.io/npm/v/@dudousxd/monad.ts.svg?maxAge=3600\" alt=\"NPM version\" /></a>\r     <a href=\"https://www.npmjs.com/package/@dudousxd/monad.ts\"><img src=\"https://img.s","homepage":"https://github.com/DavideCarvalho/monad.ts#readme","repository":{"type":"git","url":"git+https://github.com/DavideCarvalho/monad.ts.git"},"author":{"name":"Davi de Carvalho","email":"davi_carvalho96@hotmail.com","url":"https://github.com/DavideCarvalho"},"bugs":{"url":"https://github.com/DavideCarvalho/monad.ts/issues"},"license":"MIT","readme":"<p>\r\n    <a href=\"https://www.npmjs.com/package/@dudousxd/monad.ts\"><img src=\"https://img.shields.io/npm/v/@dudousxd/monad.ts.svg?maxAge=3600\" alt=\"NPM version\" /></a>\r\n    <a href=\"https://www.npmjs.com/package/@dudousxd/monad.ts\"><img src=\"https://img.shields.io/npm/dt/@dudousxd/monad.ts.svg?maxAge=3600\" alt=\"NPM downloads\" /></a>\r\n</p>\r\n\r\n# monad.ts\r\n> Monad Structure for TypeScript\r\n\r\nMonad.ts is a lib capable of giving to TypeScript the ability of having safe IO.\r\nIf you don't know what a monad is, I recommend you to [read about it.](https://medium.com/javascript-scene/javascript-monads-made-simple-7856be57bfe8)\r\n\r\ninstall it with npm or yarn  \r\n`yarn add @dudousxd/monad.ts`  \r\n`npm i @dudousxd/monad.ts`\r\n\r\nUse this lib is quite simple! You only need to import Monad and encapsulate your object inside it.\r\n\r\n```typescript\r\nimport Monad from '@dudousxd/monad.ts';\r\nconst myMonad: Monad<string> = Monad.of('Hello World');\r\n```\r\n\r\nWhen encapsulated, you have some methods to make operations on your monad.\r\n\r\n### ```bind(fn(x: any) => any): Monad<T>```\r\n\r\nThis method takes a function as argument and returns a new Monad with your desired type.\r\n\r\n```typescript\r\nconst myMonad: Monad<number[]> = Monad.of([1, 2, 3, 4, 5]);\r\nconst f = (x: number) => x + 1;\r\nconst mappedMonad: Monad<number[]> = myMonad.bind(f);\r\nconsole.log(mappedMonad.value) // [2, 3, 4, 5 , 6]\r\n```\r\n\r\nSince this method returns another Monad, you can chain methods like this:\r\n```typescript\r\nconst myMonad: Monad<number[]> = Monad.of([1, 2, 3, 4, 5]);\r\nconst f = (x: number) => x + 1;\r\nconst g = (x: number) => x * 2;\r\nconst mappedMonad: Monad<number[]> = myMonad.bind(f).bind(g);\r\nconsole.log(mappedMonad.value) //[4, 6, 8, 10, 12]\r\n```\r\n\r\nAnd of course, you can change the type of your Monad based on your operations\r\n```typescript\r\nconst myMonad: Monad<number> = Monad.of(1);\r\nconst f = (x: number): string => x.toString();\r\nconst mappedMonad: Monad<string> = myMonad.bind(f);\r\nconsole.log(typeof mappedMonad.value) //string\r\n```\r\n\r\n### ```flatMap(fn(x: any) => any): Monad<T>```\r\nAs you can see, bind and flatMap receives and returns the same stuff, there is only one little diference between them: While map\r\noperates in a single object (like an array of objects), flatMap can take several values (like an array of arrays), join them in a \r\nsingle object and then operate, e.g:\r\n\r\n```typescript\r\nconst myMonad: Monad<number[][]> = Monad.of([[1], [2, 3], [4, 5, 6]]);\r\nconst f = (x: number) => x + 1;\r\nconst mappedMonad: Monad<number[]> = myMonad.flatMap(f);\r\nconsole.log(mappedMonad.value) //[2, 3, 4, 5, 6, 7]\r\n```\r\n\r\nIf your array has any empty array, it will be unnoticed\r\n```typescript\r\nconst myMonad: Monad<number[][]> = Monad.of([[1], [], [4, 5, 6]]);\r\nconst f = (x: number) => x + 1;\r\nconst mappedMonad: Monad<number[]> = myMonad.flatMap(f);\r\nconsole.log(mappedMonad.value); // [2, 5, 6, 7]\r\n```\r\n\r\nAaand we can't forget, you can chain flatMap with bind\r\n```typescript\r\nconst myMonad: Monad<number[][]> = Monad.of([[1], [], [4, 5, 6]]);\r\nconst f = (x: number) => x + 1;\r\nconst g = (x: number) => x * 2;\r\nconst mappedMonad: Monad<number[]> = myMonad.flatMap(f).bind(g);\r\nconsole.log(mappedMonad.value); // [4, 6, 8, 10, 12, 14]\r\n```\r\n\r\n### ```either(e: Error, monadValue: any):any```\r\nThis either function is like a catch. You can define what the monad will do in case your operation throws something. This either function has to return something, otherwhise it will stop your chain.\r\nEither function receives the error and the Monad value of the bind that just throwed an error, so you do something in case of error.\r\n\r\n```typescript\r\n(error: Erorr, monadValue):any => {console.log(e); return []}\r\n```\r\nThis is the default either. It will log your error and return an empty array, e.g:\r\n\r\nfor this example, we'll create two interfaces:\r\n```typescript\r\ninterface SonJson{ \r\n  name: string;\r\n  parents: ParentsJson;\r\n}\r\n\r\ninterface ParentsJson {\r\n  dad: string;\r\n  mother: string\r\n}\r\n```\r\n\r\n```typescript\r\nconst myMonad: Monad<SonJson> = Monad.of({name: 'Son', parents: {dad: 'Dad', mother:'Mother'}});\r\nconst f = (x: SonJson):ParentsJson => x.parents;\r\nconst g = (x: any):string => x.test;\r\nconst h = (x: string):number => x.length;\r\nconst mappedMonad = myMonad.bind(f).bind(g).bind(h);\r\nconsole.log(mappedMonad.value); // []\r\n```\r\nIn the example above, g function will look for an attribute called test. Since this attribute doesn't exist, it will return undefined. After that, h function will try to get the length of undefined, so it will give you an error. To stop the error from spreading and stoping our application, either will return an empty array.\r\n\r\n\r\nEither will work and make your bindings go all the way until the end even if an error happened on your third bind and you have 4 binds, like this:\r\n```typescript\r\nconst myMonad: Monad<SonJson> = Monad.of({name: 'Son', parents: {dad: 'Dad', mother:'Mother'}});\r\nconst f = (x: SonJson):ParentsJson => x.parents;\r\nconst g = (x: any):string => x.teste;\r\nconst h = (x: string):number => x.length;\r\nconst j = (x: number):number => x*x\r\nconst mappedMonad = myMonad.bind(f).bind(g).bind(h).bind(j);\r\nconsole.log(mappedMonad.value) // []\r\n```\r\n\r\nTo define a custom either function, you only need to do:\r\n```typescript\r\nconst customEither = (error, monadValue) => {console.log('customEither'); return ''};\r\nconst myMonad: Monad<SonJson> = Monad.of({name: 'Son', parents: {dad: 'Dad', mother:'Mother'}}).setEither(customEither);\r\nconst f = (x: SonJson):ParentsJson => x.parents;\r\nconst g = (x: any):string => x.teste;\r\nconst h = (x: any):number => x.length;\r\nconst mappedMonad = myMonad.bind(f).bind(g).bind(h);\r\nconsole.log(mappedMonad.value); // ''\r\n```\r\n\r\nYou can also call setEither in the middle of a chain of bindings, this is really helpful if you want diferent either functions for different bindings\r\n```typescript\r\nconst customEitherOne = (error, monadValue) => {console.log('customEitherOne'); return ''};\r\nconst customEitherTwo = (error, monadValue) => {console.log('customEitherTwo'); return ''};\r\nconst customEitherThree = (error, monadValue) => {console.log('customEitherThree'); return []};\r\nconst myMonad: Monad<SonJson> = Monad.of({name: 'Son', parents: {dad: 'Dad', mother:'Mother'}}).setEither(customEither);\r\nconst f = (x: SonJson):ParentsJson => x.parents;\r\nconst g = (x: any):string => x.teste;\r\nconst h = (x: any):number => x.length;\r\nconst mappedMonad = myMonad\r\n                    .setEither(customEitherOne)\r\n                    .bind(f)\r\n                    .setEither(customEitherTwo)\r\n                    .bind(g)\r\n                    .setEither(customEitherThree)\r\n                    .bind(h);\r\nconsole.log(mappedMonad.value); // []\r\n```\r\n\r\nIf you need, you can set either function back to default behavior with `setDefaultEither`\r\n```typescript\r\nconst customEitherOne = (error, monadValue) => {console.log('customEitherOne'); return ''};\r\nconst customEitherTwo = (error, monadValue) => {console.log('customEitherTwo'); return ''};\r\nconst myMonad: Monad<SonJson> = Monad.of({name: 'Son', parents: {dad: 'Dad', mother:'Mother'}}).setEither(customEither);\r\nconst f = (x: SonJson):ParentsJson => x.parents;\r\nconst g = (x: any):string => x.teste;\r\nconst h = (x: any):number => x.length;\r\nconst mappedMonad = myMonad\r\n                    .setEither(customEitherOne)\r\n                    .bind(f)\r\n                    .setEither(customEitherTwo)\r\n                    .bind(g)\r\n                    .setDefaultEither()\r\n                    .bind(h);\r\nconsole.log(mappedMonad.value); // []\r\n```\r\n\r\n### Important!\r\nIt's important to remember that an either function will be passed to all the other binds, so if you set an either function that returns something valid only for my first bind, the Monad will return the either function to the default behavior\r\n```typescript\r\nconst customEither = (e: any, monadValue: any) => {\r\n  console.error('customEither');\r\n  return 3;\r\n};\r\nconst myMonad: Monad<SonJson> = Monad\r\n                                .of({name: 'Son', parents: {dad: 'Dad', mother: 'Mother'}})\r\n                                .setEither(customEither);\r\nconst f = (x: SonJson): ParentsJson => x.parents;\r\nconst g = (x: any): string => x.test;\r\nconst h = (x: any): number => x.length; // it will return 3\r\nconst i = (x: string): string => x.toUpperCase(); // it will try to uppercase 3, this will blow an error, so instead, monad will return the default behavior, in other words, will return []\r\nconst mappedMonad = myMonad\r\n                    .bind(f)\r\n                    .bind(g)\r\n                    .bind(h)\r\n                    .bind(i);\r\nconsole.log(mappedMonad.value); // []\r\n```\r\n\r\n## Monad Types\r\nSince Monads can throw error and stop your bind chain (like the cases we saw on either), they have two types to tell if everything ocurred okay or not:\r\n- Just: Monad is a Maybe if your value on `Monad.of(value)` is a valid value or your operations ocurred until the end\r\n- Nothing: If you pass a falsey value for Monad.of, like null, or an empty array, your Monad will be Nothing. If an error occured during any of your bindings, the result of your Monad will be a Nothing Monad.\r\n\r\nTo get the type of your Monad, you can use the method `getMonadType(): string`, and it will return the Monad type as a string.\r\n","readmeFilename":"README.md"}