{"_id":"daggy","_rev":"4181012","name":"daggy","description":"Library for creating tagged constructors.","dist-tags":{"latest":"1.5.0"},"maintainers":[{"name":"davidchambers","email":""},{"name":"drboolean","email":""},{"name":"jaforbes","email":""},{"name":"joneshf","email":"jones3.hardy@gmail.com"},{"name":"kennknowles","email":""},{"name":"mudge","email":"mudge@mudge.name"},{"name":"puffnfresh","email":""},{"name":"raimohanska","email":""},{"name":"raynos","email":""},{"name":"robotlolita","email":""},{"name":"safareli","email":""},{"name":"simonrichardson","email":""},{"name":"trevorbasinger","email":""}],"time":{"modified":"2026-03-01T21:49:57.000Z","created":"2013-05-30T14:45:21.546Z","1.5.0":"2021-07-19T10:37:40.423Z","1.4.0":"2019-02-14T19:52:08.008Z","1.3.0":"2018-09-12T13:18:51.471Z","1.2.0":"2017-08-04T09:59:59.323Z","1.1.0":"2017-05-26T16:34:24.146Z","1.0.0":"2017-05-03T11:16:16.100Z","0.0.1":"2013-05-30T14:45:21.546Z"},"users":{},"author":{"name":"Brian McKenna"},"repository":{"type":"git","url":"git+https://github.com/fantasyland/daggy.git"},"versions":{"1.5.0":{"name":"daggy","description":"Library for creating tagged constructors.","repository":{"type":"git","url":"git+https://github.com/fantasyland/daggy.git"},"keywords":["constructor"],"author":{"name":"Brian McKenna"},"license":"MIT","dependencies":{"sanctuary-show":"2.0.0","sanctuary-type-identifiers":"1.0.0"},"devDependencies":{"benchmark":"2.1.3","cli-table":"0.3.1","colors":"1.1.2","daggy":"1.3.0","eslint":"6.8.x","fantasy-combinators":"0.0.x","sanctuary-style":"4.0.x","standard":"8.6.0","tap":"10.0.0","xyz":"3.0.x"},"scripts":{"lint":"eslint --config node_modules/sanctuary-style/eslint-es3.json --global define --global module --global require --global self -- src/daggy.js && standard bench/*.js test/*.js","release":"xyz --repo git@github.com:fantasyland/daggy.git --increment","test":"tap -R tap test/*.js","check":"npm run lint && npm run test","bench":"node bench/"},"main":"src/daggy.js","version":"1.5.0","gitHead":"47b2f296cdcd552879816e88b01d9e70651149c3","bugs":{"url":"https://github.com/fantasyland/daggy/issues"},"homepage":"https://github.com/fantasyland/daggy#readme","_id":"daggy@1.5.0","_nodeVersion":"14.15.1","_npmVersion":"6.14.8","dist":{"shasum":"82d9818a614e018a7ebb68f53a10970493293ee8","size":4202,"noattachment":false,"key":"/daggy/-/daggy-1.5.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/daggy/download/daggy-1.5.0.tgz"},"_npmUser":{"name":"davidchambers","email":"dc@davidchambers.me"},"directories":{},"maintainers":[{"name":"davidchambers","email":""},{"name":"drboolean","email":""},{"name":"jaforbes","email":""},{"name":"joneshf","email":"jones3.hardy@gmail.com"},{"name":"kennknowles","email":""},{"name":"mudge","email":"mudge@mudge.name"},{"name":"puffnfresh","email":""},{"name":"raimohanska","email":""},{"name":"raynos","email":""},{"name":"robotlolita","email":""},{"name":"safareli","email":""},{"name":"simonrichardson","email":""},{"name":"trevorbasinger","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/daggy_1.5.0_1626691060294_0.6685233559733426"},"_hasShrinkwrap":false,"publish_time":1626691060423,"_cnpm_publish_time":1626691060423,"_cnpmcore_publish_time":"2021-12-16T20:05:16.130Z"},"1.4.0":{"name":"daggy","description":"Library for creating tagged constructors.","repository":{"type":"git","url":"git+https://github.com/fantasyland/daggy.git"},"keywords":["constructor"],"author":{"name":"Brian McKenna"},"license":"MIT","dependencies":{"sanctuary-type-classes":"3.0.0","sanctuary-type-identifiers":"1.0.0"},"devDependencies":{"benchmark":"2.1.3","cli-table":"0.3.1","colors":"1.1.2","daggy":"1.3.0","eslint":"3.19.x","fantasy-combinators":"0.0.x","sanctuary-style":"0.5.x","standard":"8.6.0","tap":"10.0.0","xyz":"3.0.x"},"scripts":{"lint":"eslint --config node_modules/sanctuary-style/eslint-es3.json --env es3 --global define --global module --global require --global self -- src/daggy.js && standard bench/*.js test/*.js","release":"xyz --repo git@github.com:fantasyland/daggy.git --increment","test":"tap -R tap test/*.js","check":"npm run lint && npm run test","bench":"node bench/"},"main":"src/daggy.js","version":"1.4.0","gitHead":"5bad6ac92fa1eb9cafb56ee8d45feb78c3f55777","bugs":{"url":"https://github.com/fantasyland/daggy/issues"},"homepage":"https://github.com/fantasyland/daggy#readme","_id":"daggy@1.4.0","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"davidchambers","email":"dc@davidchambers.me"},"dist":{"shasum":"178b4722866e1c8fac7b91d4bbf171d3767c1573","size":4152,"noattachment":false,"key":"/daggy/-/daggy-1.4.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/daggy/download/daggy-1.4.0.tgz"},"maintainers":[{"name":"davidchambers","email":""},{"name":"drboolean","email":""},{"name":"jaforbes","email":""},{"name":"joneshf","email":"jones3.hardy@gmail.com"},{"name":"kennknowles","email":""},{"name":"mudge","email":"mudge@mudge.name"},{"name":"puffnfresh","email":""},{"name":"raimohanska","email":""},{"name":"raynos","email":""},{"name":"robotlolita","email":""},{"name":"safareli","email":""},{"name":"simonrichardson","email":""},{"name":"trevorbasinger","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/daggy_1.4.0_1550173927874_0.7211864125070504"},"_hasShrinkwrap":false,"publish_time":1550173928008,"_cnpm_publish_time":1550173928008,"_cnpmcore_publish_time":"2021-12-16T20:05:16.400Z"},"1.3.0":{"name":"daggy","description":"Library for creating tagged constructors.","repository":{"type":"git","url":"git+https://github.com/fantasyland/daggy.git"},"keywords":["constructor"],"author":{"name":"Brian McKenna"},"license":"MIT","dependencies":{"sanctuary-type-classes":"3.0.0","sanctuary-type-identifiers":"1.0.0"},"devDependencies":{"benchmark":"2.1.3","cli-table":"0.3.1","colors":"1.1.2","daggy":"1.0.0","eslint":"3.19.x","fantasy-combinators":"0.0.x","sanctuary-style":"0.5.x","standard":"8.6.0","tap":"10.0.0","xyz":"3.0.x"},"scripts":{"lint":"eslint --config node_modules/sanctuary-style/eslint-es3.json --env es3 --global define --global module --global require --global self -- src/daggy.js && standard bench/*.js test/*.js","release":"xyz --repo git@github.com:fantasyland/daggy.git --increment","test":"tap -R tap test/*.js","check":"npm run lint && npm run test","bench":"node bench/"},"main":"src/daggy.js","version":"1.3.0","gitHead":"0b7f3eb934e7b2969eefc33b89134eeb16e9c095","bugs":{"url":"https://github.com/fantasyland/daggy/issues"},"homepage":"https://github.com/fantasyland/daggy#readme","_id":"daggy@1.3.0","_npmVersion":"6.4.1","_nodeVersion":"10.10.0","_npmUser":{"name":"davidchambers","email":"dc@davidchambers.me"},"dist":{"shasum":"9cc687797e000363ec51ec8b41819f6bceac26be","size":3659,"noattachment":false,"key":"/daggy/-/daggy-1.3.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/daggy/download/daggy-1.3.0.tgz"},"maintainers":[{"name":"davidchambers","email":""},{"name":"drboolean","email":""},{"name":"jaforbes","email":""},{"name":"joneshf","email":"jones3.hardy@gmail.com"},{"name":"kennknowles","email":""},{"name":"mudge","email":"mudge@mudge.name"},{"name":"puffnfresh","email":""},{"name":"raimohanska","email":""},{"name":"raynos","email":""},{"name":"robotlolita","email":""},{"name":"safareli","email":""},{"name":"simonrichardson","email":""},{"name":"trevorbasinger","email":""}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/daggy_1.3.0_1536758331197_0.017685700241858227"},"_hasShrinkwrap":false,"publish_time":1536758331471,"_cnpm_publish_time":1536758331471,"_cnpmcore_publish_time":"2021-12-16T20:05:16.623Z"},"1.2.0":{"name":"daggy","description":"Library for creating tagged constructors.","repository":{"type":"git","url":"git+https://github.com/fantasyland/daggy.git"},"keywords":["constructor"],"author":{"name":"Brian McKenna"},"license":"MIT","dependencies":{"sanctuary-type-classes":"3.0.0","sanctuary-type-identifiers":"1.0.0"},"devDependencies":{"benchmark":"2.1.3","cli-table":"0.3.1","colors":"1.1.2","daggy":"1.0.0","eslint":"3.19.x","fantasy-combinators":"0.0.x","sanctuary-style":"0.5.x","standard":"8.6.0","tap":"10.0.0","xyz":"2.1.x"},"scripts":{"lint":"eslint --config node_modules/sanctuary-style/eslint-es3.json --env es3 --global define --global module --global require --global self -- src/daggy.js && standard bench/*.js test/*.js","release-major":"xyz --repo git@github.com:fantasyland/daggy.git --increment major","release-minor":"xyz --repo git@github.com:fantasyland/daggy.git --increment minor","release-patch":"xyz --repo git@github.com:fantasyland/daggy.git --increment patch","test":"tap -R tap test/*.js","check":"npm run lint && npm run test","bench":"node bench/"},"files":["src/*.js"],"main":"src/daggy.js","version":"1.2.0","gitHead":"6d49954d9918e78acefca765e95ea007a676b0a8","bugs":{"url":"https://github.com/fantasyland/daggy/issues"},"homepage":"https://github.com/fantasyland/daggy#readme","_id":"daggy@1.2.0","_shasum":"f0151fcffd58f1742d63d8c53a7556e84b258cb4","_from":".","_npmVersion":"3.10.10","_nodeVersion":"6.11.1","_npmUser":{"name":"davidchambers","email":"dc@davidchambers.me"},"dist":{"shasum":"f0151fcffd58f1742d63d8c53a7556e84b258cb4","size":3482,"noattachment":false,"key":"/daggy/-/daggy-1.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/daggy/download/daggy-1.2.0.tgz"},"maintainers":[{"name":"davidchambers","email":""},{"name":"drboolean","email":""},{"name":"jaforbes","email":""},{"name":"joneshf","email":"jones3.hardy@gmail.com"},{"name":"kennknowles","email":""},{"name":"mudge","email":"mudge@mudge.name"},{"name":"puffnfresh","email":""},{"name":"raimohanska","email":""},{"name":"raynos","email":""},{"name":"robotlolita","email":""},{"name":"safareli","email":""},{"name":"simonrichardson","email":""},{"name":"trevorbasinger","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/daggy-1.2.0.tgz_1501840798472_0.21467466582544148"},"directories":{},"publish_time":1501840799323,"_hasShrinkwrap":false,"_cnpm_publish_time":1501840799323,"_cnpmcore_publish_time":"2021-12-16T20:05:16.824Z"},"1.1.0":{"name":"daggy","description":"Library for creating tagged constructors.","repository":{"type":"git","url":"git+https://github.com/fantasyland/daggy.git"},"keywords":["constructor"],"author":{"name":"Brian McKenna"},"license":"MIT","dependencies":{"sanctuary-type-classes":"3.0.0","sanctuary-type-identifiers":"1.0.0"},"devDependencies":{"benchmark":"2.1.3","cli-table":"0.3.1","colors":"1.1.2","daggy":"1.0.0","fantasy-combinators":"0.0.x","standard":"8.6.0","tap":"10.0.0","xyz":"2.1.x"},"scripts":{"lint":"standard bench/*.js src/*.js test/*.js","lint:fix":"npm run lint -- --fix","release-major":"xyz --repo git@github.com:fantasyland/daggy.git --increment major","release-minor":"xyz --repo git@github.com:fantasyland/daggy.git --increment minor","release-patch":"xyz --repo git@github.com:fantasyland/daggy.git --increment patch","test":"tap -R tap test/*.js","check":"npm run lint && npm run test","bench":"node bench/"},"files":["src/*.js"],"main":"src/daggy.js","version":"1.1.0","gitHead":"f78cfda96a199ee59dc46a5659e8c06a46208b08","bugs":{"url":"https://github.com/fantasyland/daggy/issues"},"homepage":"https://github.com/fantasyland/daggy#readme","_id":"daggy@1.1.0","_shasum":"375995a869f4f18022a0fa92de5caa2df6921fc8","_from":".","_npmVersion":"3.10.8","_nodeVersion":"7.0.0","_npmUser":{"name":"safareli","email":"i.safareli@gmail.com"},"dist":{"shasum":"375995a869f4f18022a0fa92de5caa2df6921fc8","size":2577,"noattachment":false,"key":"/daggy/-/daggy-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/daggy/download/daggy-1.1.0.tgz"},"maintainers":[{"name":"davidchambers","email":""},{"name":"drboolean","email":""},{"name":"jaforbes","email":""},{"name":"joneshf","email":"jones3.hardy@gmail.com"},{"name":"kennknowles","email":""},{"name":"mudge","email":"mudge@mudge.name"},{"name":"puffnfresh","email":""},{"name":"raimohanska","email":""},{"name":"raynos","email":""},{"name":"robotlolita","email":""},{"name":"safareli","email":""},{"name":"simonrichardson","email":""},{"name":"trevorbasinger","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/daggy-1.1.0.tgz_1495816463292_0.09144071722403169"},"directories":{},"publish_time":1495816464146,"_hasShrinkwrap":false,"_cnpm_publish_time":1495816464146,"_cnpmcore_publish_time":"2021-12-16T20:05:17.032Z"},"1.0.0":{"name":"daggy","description":"Library for creating tagged constructors.","repository":{"type":"git","url":"git+https://github.com/fantasyland/daggy.git"},"keywords":["constructor"],"author":{"name":"Brian McKenna"},"license":"MIT","dependencies":{"sanctuary-type-classes":"3.0.0","sanctuary-type-identifiers":"1.0.0"},"devDependencies":{"benchmark":"2.1.3","cli-table":"0.3.1","colors":"1.1.2","daggy":"github:fantasyland/daggy#8ef74ee0b90bbace396f48d1a5e20347f0297478","fantasy-combinators":"0.0.x","standard":"8.6.0","tap":"10.0.0","xyz":"2.1.x"},"scripts":{"lint":"standard bench/*.js src/*.js test/*.js","lint:fix":"npm run lint -- --fix","release-major":"xyz --repo git@github.com:fantasyland/daggy.git --increment major","release-minor":"xyz --repo git@github.com:fantasyland/daggy.git --increment minor","release-patch":"xyz --repo git@github.com:fantasyland/daggy.git --increment patch","test":"tap -R tap test/*.js","check":"npm run lint && npm run test","bench":"node bench/"},"files":["src/*.js"],"main":"src/daggy.js","version":"1.0.0","gitHead":"67bd910a0a5239f3696dd0597315905375e8d8a8","bugs":{"url":"https://github.com/fantasyland/daggy/issues"},"homepage":"https://github.com/fantasyland/daggy#readme","_id":"daggy@1.0.0","_shasum":"dffb77b0b481d124251c80b2f7d1311f9f74b44c","_from":".","_npmVersion":"3.10.3","_nodeVersion":"6.5.0","_npmUser":{"name":"davidchambers","email":"dc@davidchambers.me"},"dist":{"shasum":"dffb77b0b481d124251c80b2f7d1311f9f74b44c","size":2414,"noattachment":false,"key":"/daggy/-/daggy-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/daggy/download/daggy-1.0.0.tgz"},"maintainers":[{"name":"davidchambers","email":""},{"name":"drboolean","email":""},{"name":"jaforbes","email":""},{"name":"joneshf","email":"jones3.hardy@gmail.com"},{"name":"kennknowles","email":""},{"name":"mudge","email":"mudge@mudge.name"},{"name":"puffnfresh","email":""},{"name":"raimohanska","email":""},{"name":"raynos","email":""},{"name":"robotlolita","email":""},{"name":"safareli","email":""},{"name":"simonrichardson","email":""},{"name":"trevorbasinger","email":""}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/daggy-1.0.0.tgz_1493810175400_0.600596678443253"},"directories":{},"publish_time":1493810176100,"_hasShrinkwrap":false,"_cnpm_publish_time":1493810176100,"_cnpmcore_publish_time":"2021-12-16T20:05:17.279Z"},"0.0.1":{"name":"daggy","version":"0.0.1","description":"Library for creating tagged constructors.","main":"daggy.js","scripts":{},"repository":{"type":"git","url":"git://github.com/puffnfresh/daggy.git"},"keywords":["constructor"],"author":{"name":"Brian McKenna"},"license":"MIT","readmeFilename":"README.htm","devDependencies":{"emu":"0.0.2"},"bugs":{"url":"https://github.com/puffnfresh/daggy/issues"},"_id":"daggy@0.0.1","dist":{"shasum":"ae9c932c9f7136e655a04afb21e8baadfd0d3707","size":3215,"noattachment":false,"key":"/daggy/-/daggy-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/daggy/download/daggy-0.0.1.tgz"},"_from":".","_npmVersion":"1.2.23","_npmUser":{"name":"puffnfresh","email":"brian@brianmckenna.org"},"maintainers":[{"name":"davidchambers","email":""},{"name":"drboolean","email":""},{"name":"jaforbes","email":""},{"name":"joneshf","email":"jones3.hardy@gmail.com"},{"name":"kennknowles","email":""},{"name":"mudge","email":"mudge@mudge.name"},{"name":"puffnfresh","email":""},{"name":"raimohanska","email":""},{"name":"raynos","email":""},{"name":"robotlolita","email":""},{"name":"safareli","email":""},{"name":"simonrichardson","email":""},{"name":"trevorbasinger","email":""}],"directories":{},"publish_time":1369925121546,"_hasShrinkwrap":false,"_cnpm_publish_time":1369925121546,"_cnpmcore_publish_time":"2021-12-16T20:05:17.494Z"}},"readme":"# Daggy\n\n[![Build Status](https://img.shields.io/travis/fantasyland/daggy/master.svg)](https://travis-ci.org/fantasyland/daggy)\n[![npm](https://img.shields.io/npm/v/daggy.svg)](https://www.npmjs.com/package/daggy)\n\nLibrary for creating tagged constructors a.k.a. \"disjoint union types\" or \"sum types\".\n\n## Motivation\n\nJavaScript does not have first class support for sum types, but they can be imitated in a handful of different ways. Nevertheless, this imitation leads to excess boilerplate that can lead to extra work and the potential for errors:\n\n```javascript\nconst successCase = { success: true, items: [1, 2, 3] }\nconst failureCase = { success: false, error: 'There was a problem.' }\n\nfunction handleResult(result) {\n  if (result.success) {\n    console.log(result.items)\n  } else {\n    console.error(result.error)\n  }\n}\n```\n\nDaggy reduces the boilerplate needed to represent sum types in JavaScript:\n\n```javascript\nconst Result = daggy.taggedSum('Result', {\n  Success: ['items'],\n  Failure: ['error']\n})\n\nconst successCase = Result.Success([1, 2, 3])\nconst failureCase = Result.Failure('There was a problem.')\n\nfunction handleResult(result) {\n  result.cata({\n    Success: message => console.log(message),\n    Failure: error => console.error(error)\n  })\n}\n```\n\n## API\n\n### `daggy.tagged(typeName, fields)`\n\nCreates a new constructor with the given field names\n\n```javascript\nconst Point3D = daggy.tagged('Point3D', ['x', 'y', 'z'])\nPoint3D.toString() // 'Point3D'\nconst a = Point3D(1, 2, 3) // { x: 1, y: 2, z: 3 }\na.x == 1 && a.y == 2 && a.z == 3 // true\na.toString() // 'Point3D(1, 2, 3)'\nPoint3D.is(a) // true\nPoint3D.prototype.scale = function(n){\n  return Point3D(this.x * n, this.y * n, this.z * n)\n}\nconst b = a.scale(2) // { x: 2, y: 4, z: 6 }\nb.toString() // 'Point3D(2, 4, 6)'\nconst c = Point3D.from({y: 2, x: 1, z: 3}) // { x: 1, y: 2, z: 3 }\n```\n\n### `daggy.taggedSum(typeName, constructors)`\n\nReturns Type Representative containing constructors of for each key in `constructors` as a property. Allows `{TypeRep}.is` and `{TypeRep}.{Tag}.is` checks for values created by constructors.\n\n```javascript\nconst Option = daggy.taggedSum('Option', {\n  Some: ['x'],\n  None: [],\n})\nconst a = Option.Some(1) // { x: 1 }\na.toString() // 'Option.Some(1)'\nOption.Some.is(a) // true\nOption.is(a) // true\nOption.None.is(Option.None) // true\nOption.is(Option.None) // true\nOption.None.toString() // 'Option.None'\nOption.Some.toString() // 'Option.Some'\nOption.prototype.map = function (f) {\n  return this.cata({\n    Some: (x) => Option.Some(f(x)),\n    None: () => this,\n  })\n}\nconst b = a.map(x => x+1) // { x: 2 }\nb.toString() // 'Option.Some(2)'\nconst c = Option.Some.from({x: 1}) // { x: 1 }\n```\n","_attachments":{},"homepage":"https://github.com/fantasyland/daggy#readme","bugs":{"url":"https://github.com/fantasyland/daggy/issues"},"license":"MIT"}