{"_id":"@astuanax/fun-monads","_rev":"1-10160de232bf6afaf8927d6d2a62a43a","name":"@astuanax/fun-monads","dist-tags":{"latest":"0.0.0"},"versions":{"0.0.0":{"name":"@astuanax/fun-monads","version":"0.0.0","description":"A monad library modelled after scala's monads.","keywords":[],"main":"dist/fun-monads.umd.js","module":"dist/fun-monads.es5.js","typings":"dist/types/fun-monads.d.ts","author":{"name":"astuanax","email":"len.dierickx@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/astuanax/fun-monads.git"},"license":"MIT","engines":{"node":">=6.0.0"},"scripts":{"lint":"tslint  --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'","prebuild":"rimraf dist","build":"tsc --module commonjs && rollup -c rollup.config.ts && typedoc --out docs --target es6 --theme default --mode file src","start":"rollup -c rollup.config.ts -w","test":"jest --coverage","test:watch":"jest --coverage --watch","test:prod":"npm run lint && npm run test -- --no-cache","deploy-docs":"ts-node tools/gh-pages-publish","report-coverage":"cat ./coverage/lcov.info | coveralls","commit":"git-cz","semantic-release":"semantic-release","semantic-release-prepare":"ts-node tools/semantic-release-prepare","precommit":"lint-staged","travis-deploy-once":"travis-deploy-once"},"lint-staged":{"{src,test}/**/*.ts":["prettier --write","git add"]},"config":{"commitizen":{"path":"node_modules/cz-conventional-changelog"}},"jest":{"transform":{".(ts|tsx)":"ts-jest"},"testEnvironment":"node","testRegex":"(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$","moduleFileExtensions":["ts","tsx","js"],"coveragePathIgnorePatterns":["/node_modules/","/test/"],"coverageThreshold":{"global":{"branches":80,"functions":60,"lines":80,"statements":80}},"collectCoverageFrom":["src/*.ts","src/Reader/*.ts","src/Option/*.ts","src/Try/*.ts","src/Either/*.ts"]},"prettier":{"semi":false,"singleQuote":true},"commitlint":{"extends":["@commitlint/config-conventional"]},"devDependencies":{"@commitlint/cli":"^7.1.2","@commitlint/config-conventional":"^7.1.2","@types/jest":"^23.3.2","@types/node":"^10.11.0","colors":"^1.3.2","commitizen":"^3.0.0","coveralls":"^3.0.2","cross-env":"^5.2.0","cz-conventional-changelog":"^2.1.0","husky":"^1.0.1","jest":"^24.9.0","jest-config":"^24.9.0","lint-staged":"^8.0.0","lodash.camelcase":"^4.3.0","prettier":"^1.14.3","prompt":"^1.0.0","replace-in-file":"^3.4.2","rimraf":"^2.6.2","rollup":"^0.67.0","rollup-plugin-commonjs":"^9.1.8","rollup-plugin-json":"^3.1.0","rollup-plugin-node-resolve":"^3.4.0","rollup-plugin-sourcemaps":"^0.4.2","rollup-plugin-typescript2":"^0.27.0","semantic-release":"^15.9.16","shelljs":"^0.8.3","travis-deploy-once":"^5.0.9","ts-jest":"^23.10.2","ts-node":"^7.0.1","tslint":"^5.11.0","tslint-config-prettier":"^1.15.0","tslint-config-standard":"^8.0.1","typedoc":"^0.17.6","typescript":"^3.0.3"},"gitHead":"66d32302f332ef3f9ab1afbef3d235d204d432d1","bugs":{"url":"https://github.com/astuanax/fun-monads/issues"},"homepage":"https://github.com/astuanax/fun-monads#readme","_id":"@astuanax/fun-monads@0.0.0","_nodeVersion":"13.12.0","_npmVersion":"6.14.4","dist":{"integrity":"sha512-Cdt8CfW5D7AyrZuInWEsNssKat4YAhJKhY1ibJPi4B5qp0PdQEixyZ3RoRRae8UkL7IIj5ixO6+fKANTv9qitg==","shasum":"3f66ac60cfe6e88363ef5ba4abe870b6eaff8103","tarball":"https://registry.npmjs.org/@astuanax/fun-monads/-/fun-monads-0.0.0.tgz","fileCount":28,"unpackedSize":176595,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJeuU/nCRA9TVsSAnZWagAABHMP/iP28ouRx7XKA+j7RG4X\nBOZmiqry3eOr93xuQ5+aXr1N94SDYS+UDVvNHwSguT9dejVBmnGRUPjLMYDU\nQFJRUlW74UTEVAtvLNPyANzDtVaAdBsTPr3fFdvqnjyzPEmfXuoG8OZ+stwn\nFoBXAv2F+i7c9jcnFsHDvvyyYOMa+sEQ+6k/oAYSNnJn7sQUFgD7S7mGG53w\nxaMwei7UVbpOhvTodejEiI0Yq9OxB50GMqH87ddb1Onxv1dBmj3T0OAlZNAE\nCsPZJRO/w8BkZD8fHUPk2q+OQWj8HFxvZ+XVCV9oC71+5qDz8uxxgPzs///H\n9Njhh0+3gKJlPNfT7wLpgFoUUAWpCc3tx/EtVh3YXzRpp7vgW/BLRwzQm4VB\naKWubPm2lUxip8TqG+rZH/fDaxLph+wGp9wutoHp8cSPLD64l2pnWnGAenoB\nRoa6jJvY7sSzTlXZnZv1HDtIbrTPUfxWreUEMFw81hDdJJ+PWH+OehmjZB/h\niZ11xz9py+pzEyAMEE58pkhXOryTeDA65kAiaf2bFk+KdagjP6mdTR01zGft\n/XOM8B2ooAh3ncc0J4YvzrHjL2Wz4crsbj7yQ2C12Whd/G5MMBkIyyRhr6D/\nGOFENvBUFSYupAlw4E6xGAcckFnyX1tGLomw/efHH1/Z5P/QigPH6Y5/XarP\nzG7a\r\n=JsKY\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCICRTnT38EVwR6tiRCTVsJfZrhikDu5Tcg3E1kMXbbIDpAiAWBrleeu96dMgxMPJRGp5rvlCtx+U43xtJCQpmM3bKDg=="}]},"maintainers":[{"name":"astuanax","email":"len.dierickx@gmail.com"}],"_npmUser":{"name":"astuanax","email":"len.dierickx@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/fun-monads_0.0.0_1589202918737_0.5332245220574521"},"_hasShrinkwrap":false}},"time":{"created":"2020-05-11T13:15:18.678Z","0.0.0":"2020-05-11T13:15:18.818Z","modified":"2022-04-04T15:59:49.171Z"},"maintainers":[{"name":"astuanax","email":"len.dierickx@gmail.com"}],"description":"A monad library modelled after scala's monads.","homepage":"https://github.com/astuanax/fun-monads#readme","keywords":[],"repository":{"type":"git","url":"git+https://github.com/astuanax/fun-monads.git"},"author":{"name":"astuanax","email":"len.dierickx@gmail.com"},"bugs":{"url":"https://github.com/astuanax/fun-monads/issues"},"license":"MIT","readme":"# fun-monads\n\nA monad library modelled after scala's monads.\n\n[![Coverage Status](https://coveralls.io/repos/github/astuanax/fun-monads/badge.svg?branch=master)](https://coveralls.io/github/astuanax/fun-monads?branch=master)\n\n## Option\nUse the of() or apply() function to create an option\n```typescript\nconst o = Option.apply(1)\nconst x = Option.of(userObj)\n```\n\nThe Option monad is not nullable and should never contain null or undefined.\n\nBelow examples will all return None \n```typescript\nconst s: None<any> = new None<any>()\nconst t: None<any> = Option.none\nconst u: None<any> = Option(null)\nconst v: None<any> = Option(undefined)\nconst w: None<any> = Option.some(null)\nconst x: None<any> = Option.some(undefined)\nconst y: None<any> = Option.apply(null)\nconst z: None<any> = Option.apply(undefined)\n```\n\n### Example\n```typescript\nconst user:Option<User> = db.GetUser(123456)\n\nreturn user\n  .filter(user => user.admin === true)\n  .map(x => loadAdminData(x))\n  .getOrElse(\"No admin data found\")    \n```\n\n## Either\nThe Either monad is right biased but has a left and right projection.\n```typescript\nconst user = Either.of(userObj)\nconst user = Either.apply(userObj)\n\nconst user = userObj.admin === false ? Left(userObj) : Right(userObj)\n```\n\n### Example\n```typescript\nconst user: Either<User, Admin> = userObj.admin === false \n  ? Left(userObj) \n  : Right(userObj)\n\nuser.map(x => loadAdminData(x))\n  .fold(u => getUser(u), a => => getAdmin(a))  \n```\n\n\n\n## Reader\nThe Reader monad can be used for dependency injection\n\nUse the of() and apply() function to create a new Reader\n```typescript\nconst r = Reader.of(x => 2*x)\nconst db = Reader.of(db => db.getType())\n```\n\n### Example\n```typescript\nconst getUser: Reader<User, Db> = userId => Reader.apply(db => db.getUser(userId))\n\nconst john = getUser(1)\nconst adam = getUser(5)\n\njohn.run(couchbaseDb)\nadam.run(postgresDb)\n```\n\n## Try\nThe Try monad is right/success biased. \n\nTry catch monad, use of() and or apply() function\n```typescript\nconst r = Try.apply(() => getDb())\nconst db = Try.apply(() => getFile(\"/path/to/file\"))\n```\n\n### Example\n```typescript\nconst getUser: Reader<User, Try<DB>> = userId => Reader.apply(db => Try(() => db.getUser(userId)))\nconst user: Try<User> = getUser(123).run(couchbaseDb)\n\nuser.map(x => getUserInfo(x))\n  .fold(err=> logAndUiError(err), s => renderUser(s))  \n```\n","readmeFilename":"README.md"}