{"_id":"@antrikshsaini/tree-npm","_rev":"2-e3243ac147350bff12415cf832e807a1","name":"@antrikshsaini/tree-npm","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"@antrikshsaini/tree-npm","version":"1.0.0","description":"Tree package for practice","homepage":"https://github.com/antrikshsaini/tree-npm","bugs":{"url":"https://github.com/antrikshsaini/issues"},"repository":{"type":"git","url":"git+https://github.com/antrikshsaini/tree-npm.git"},"license":"UNLICENSED","author":{"name":"antrikshsaini"},"type":"module","exports":"./dist/index.js","module":"dist/index.js","types":"dist/index.d.ts","devDependencies":{"@types/node":"^14.11.2","gts":"^3.1.0","typescript":"^4.0.3"},"scripts":{"lint":"gts lint","clean":"gts clean","compile":"tsc","fix":"gts fix","prepare":"npm run compile","pretest":"npm run compile","posttest":"npm run lint","build":"tsc","test":"jest"},"engines":{"node":">=6.0.0"},"gitHead":"0f94259a3d98c2f30650ff998eb51fb52e67a0f9","_id":"@antrikshsaini/tree-npm@1.0.0","_nodeVersion":"16.9.1","_npmVersion":"7.21.1","dist":{"integrity":"sha512-pS805uSyXHJsgqdNt/Dp6uCBpQ/WsAm7J8WHVXRX0peV5+cMEOpmnVeJLeVrlgWU878lH2CKCn93ahOj87/SoQ==","shasum":"b4be2bcf7dfa655f47658e29ac12b6df8ea51ab2","tarball":"https://registry.npmjs.org/@antrikshsaini/tree-npm/-/tree-npm-1.0.0.tgz","fileCount":6,"unpackedSize":13791,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiHk+AACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmoHrw//e1Q8kunTfYI2aKu5KAZGkXqmxDZzmp1SsWJkSRSX0xtMsIGJ\r\n/34lEdj3yjggfSHRpJzKr+vZMrRkTHRsSr0QEnL54B1oU2tRZgL2t4TP+oi+\r\nvahMShMlhuw8DCcBPsrBCgGddRl7OMsWafCCuZrCIY3lucUkV1PNij/w5gx+\r\nCOGU7j+eSRiBDTIhIf9lZPiTJw+L1+fpEl7ODm/wS8/vqU/Nukgj18UVpeYZ\r\nyC0fslovzpg0PDGdKqT2yYTVB4C8VZs/mAeM4HXboFMaTn1RO6omZwfc3Jhy\r\nAIslubw8FDk84oPW7/fbsF3CmArOeg9WqOXMt8J/Tl56AnYVmrcUBeQd5xGC\r\n6GwOVdHDNmu49gFqT1efQSj47UAT/E+5FApJ+91PA21YuUmQCWVOh7KCr/6M\r\nKZvQvY72gN7lYA95YnMfII/5azcsryAB5uBLOVuKq1Wc9+kdCFMyhjXZo8Cx\r\nOXe/oC1KPhm0udrqFEihCAt2qXGe+nAvm164RnYO850agFElK8Ew6CU7amME\r\npLo8qa/OGwroqMfQc+bvO2Nds7YanzVzqqchVzooMprZHDTYkW8SRAxE/rTG\r\nfOXqp2M5F5eMUlecb7fK1SIPXMt2efJe4rRBiFa9oGkgL5spLPeM2nyDFaqq\r\nGo2hbGzY285NWh9jrSdZYijWamSdp8FUNDE=\r\n=SZPz\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIHMCwCQSf5F94jDhyTQV9XVrtyyfLXMMjmgKQDh+T1QNAiEAoAt4pPoBh2RhWlX3jPGItZkF3/BzOGVwpvXCfblKq6c="}]},"_npmUser":{"name":"antrikshsaini","email":"antriksh@vividtheory.com"},"directories":{},"maintainers":[{"name":"antrikshsaini","email":"antriksh@vividtheory.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/tree-npm_1.0.0_1646153599890_0.7934963309394398"},"_hasShrinkwrap":false},"1.1.0":{"name":"@antrikshsaini/tree-npm","version":"1.1.0","description":"Tree package for practice","homepage":"https://github.com/antrikshsaini/tree-npm","bugs":{"url":"https://github.com/antrikshsaini/issues"},"repository":{"type":"git","url":"git+https://github.com/antrikshsaini/tree-npm.git"},"license":"UNLICENSED","author":{"name":"antrikshsaini"},"type":"module","exports":"./dist/index.js","module":"dist/index.js","types":"dist/index.d.ts","devDependencies":{"@types/node":"^14.11.2","gts":"^3.1.0","typescript":"^4.0.3"},"scripts":{"lint":"gts lint","clean":"gts clean","compile":"tsc","fix":"gts fix","prepare":"npm run compile","pretest":"npm run compile","posttest":"npm run lint","build":"tsc","test":"jest"},"engines":{"node":">=6.0.0"},"gitHead":"0f57078bc80d71c2f7afe2ea8c9d1a76bf5ec54d","_id":"@antrikshsaini/tree-npm@1.1.0","_nodeVersion":"16.9.1","_npmVersion":"7.21.1","dist":{"integrity":"sha512-ZgPM8ZgglRAp2WhR95F+8j/EOXagEJNrEF/rT8rHTY8X4lw+/FQHvZQshPFOx3hYsXqCKFr1aVvNvtojSMWZnw==","shasum":"8436f3fa3b33759250115bfbcfc04caa80ec7616","tarball":"https://registry.npmjs.org/@antrikshsaini/tree-npm/-/tree-npm-1.1.0.tgz","fileCount":6,"unpackedSize":14097,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiHo2IACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqkqg/6A3U5PpmbrpAVmc527tPtw5VIzBYdqbuB6OfemoibKAjFCHdp\r\nco9ASpTMwynzWK7p8BPyQd0PgZGfFXQnLZUn+ccBuHhtqcg1/fguWgW3yuyE\r\nm+K6uKS6g2BKRlQQkHPpIhG1u072q8gNNk/CKr2A2XkVdVtUL98MVq47kq5y\r\nkLpeBrWfoZ+Y3x5NiiM3mcOS4+wyfC4TaH6tdSPJqHDhqVUpWYmqf6dAH6Q0\r\nIpjQ4Nc0HwV/8HcHCIxgXH+X0LW8gm2ePRJo1eonIQ+/Vkj9m24+qLXIFdUF\r\noRMemZtamjYpPxtHvk9H0z0+e5/Fz3BqH78DBLikOKh6kEXc6WYKqjZX36of\r\nEDx/F1QZXvWoUOvmoVH2nQA+s213+doYik7JVpDPn3nJlwbQ6WNbc17WPnSS\r\nmCYEh03cs84911DnN4xY6T0wLeu6/1UWf/0xt4jjhEigFMqbnnvxQNhMpc0O\r\n2nrK61xw2lkyDYXxOw2WvOeaivIO0QBu8WQftIDnnfUcpbU+vSSbHqxk44nD\r\n4sTIiud/1jZ0Qz0zSU7QuvCc2FxB+v/lMFewOj/j6I86BuzVgUbI4VB0VZHg\r\nLYXZx73J48nutCKGx5TZvVncDIxBRv8rlITiSEhAFunQ0GTYryDlyPub1Hsv\r\nSf17fWxJaqJhapGggIjdXRQ7KGTzKQ4mTmU=\r\n=q0vX\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCkl2pouujTHo6DPVL1I2Kc4wtIAy/6/xnM7q5TSzJ/+gIgY7tK+p/5zyK14Rmduz6ThNDwZHw6WjeSQhP9kyrjhf4="}]},"_npmUser":{"name":"antrikshsaini","email":"antriksh@vividtheory.com"},"directories":{},"maintainers":[{"name":"antrikshsaini","email":"antriksh@vividtheory.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/tree-npm_1.1.0_1646169480585_0.9619827308140068"},"_hasShrinkwrap":false}},"time":{"created":"2022-03-01T16:53:19.842Z","1.0.0":"2022-03-01T16:53:20.039Z","modified":"2022-04-04T14:23:44.921Z","1.1.0":"2022-03-01T21:18:00.707Z"},"maintainers":[{"name":"antrikshsaini","email":"antriksh@vividtheory.com"}],"description":"Tree package for practice","homepage":"https://github.com/antrikshsaini/tree-npm","repository":{"type":"git","url":"git+https://github.com/antrikshsaini/tree-npm.git"},"author":{"name":"antrikshsaini"},"bugs":{"url":"https://github.com/antrikshsaini/issues"},"license":"UNLICENSED","readme":"# Tree npm package \n\n## Installation\n\nuse command ``` npm install tree-npm-lib ``` to install package\n\n## Some Explanation\n\n\n\n                          A Tree\n\n                          Branch\n                      ┌─────┬─────┐\n             ┌────────┼──●  │  ●──┼───────┐\n             │        └─────┴─────┘       │\n             ↓         left  right        ↓\n           Branch                       Branch\n\n### Type Declaration\n\n```ts\ntype Tree<A> = Leaf<A> | Branch<A>;\n\nclass Leaf<A> {\n    tag: 'leaf' = 'leaf';\n    readonly value: A;\n\n    constructor(value: A) {\n        this.value = value;\n    }\n}\n\nclass Branch<A> {\n    tag: 'branch' = 'branch';\n    readonly left: Tree<A>;\n    readonly right: Tree<A>;\n\n    constructor(left: Tree<A>, right: Tree<A>) {\n        this.left = left;\n        this.right = right;\n    }\n}\n\nclass BranchOptional<A> {\n    tag: 'branchOptional' = 'branchOptional';\n    readonly left?: TreeOptional<A>;\n    readonly right?: TreeOptional<A>;\n\n    constructor(option: { left?: TreeOptional<A>, right?: TreeOptional<A> }) {\n        this.left = option.left;\n        this.right = option.right;\n    }\n}\n\ntype TreeOptional<A> = Leaf<A> | BranchOptional<A>\n\nconst isBranchOptional = <A>(t: TreeOptional<A>): t is BranchOptional<A> => {\n    return t.tag === 'branchOptional';\n};\n\n```\n### Type Guards\n\n```ts\n\nconst isLeaf = <A>(t: Tree<A>): t is Leaf<A> => {\n    return t.tag === 'leaf';\n};\nconst isBranch = <A>(t: Tree<A>): t is Branch<A> => {\n    return t.tag === 'branch';\n};\n\n```\n\n## Some Cool Functions\n\n### Size   \nSignature->   size: Tree<A> -> number\n\nFind size of Tree, Total of number of leaf and branch\n\n```ts\nconst tree: Tree<number> = {\n  tag: 'branch',\n  left: {tag: 'leaf', value: 8},\n  right: {\n    tag: 'branch',\n    left: {tag: 'leaf', value: 5},\n    right: {tag: 'leaf', value: 9},\n  },\n};\nconsole.log(size(tree)); // 3\n\n```\n\n### Max\nSignature->   max: Tree<number> -> number\n\nIn a Tree of type number, find Maximum leaf value\n\n```ts\nconsole.log(max(tree)); //9\n```\n\n### Depth\nSignature->   depth: Tree<A> -> number\n\nIn a Tree, find the maximum path length from the root node to any leaf\n\n```ts\nconsole.log(depth(tree)); // 2\n```\n\n### Map\nSignature->   map: ((A)-> B) -> Tree<A> -> Tree<B>\n\nCreates new Tree, after applying a function to each element in the tree\n\n```ts\nconst tree: Tree<number> = {\n  tag: 'branch',\n  left: {tag: 'leaf', value: 2},\n  right: {\n    tag: 'branch',\n    left: {tag: 'leaf', value: 3},\n    right: {tag: 'leaf', value: 4},\n  },\n};\nconsole.log(map((i) => i + 1, tree));\n\nconsole.log(mapCurry((i: number) => i + 1)(tree));\n\n//Output\nBranch { tag: 'branch',\n    left: Leaf { tag: 'leaf', value: 3 },\n    right: Branch {\n        tag: 'branch',\n        left: Leaf { tag: 'leaf', value: 4 },\n        right: Leaf { tag: 'leaf', value: 5 }\n        }\n    }\n```\n### Filter\nSignature->   filter : ((Tree<A>)=> boolean) => Tree<A> | undefined => Tree<A> | undefined\n\nCreates a tree or return undefined, based on the condition (basically remove leaf node)\n\n```ts\nconst tree: Tree<number> = {\n    tag: 'branch',\n    left: { tag: 'leaf', value: 2 },\n    right: {\n        tag: 'branch',\n        left: { tag: 'leaf', value: 5 },\n        right: { tag: 'leaf', value: 4 },\n    },\n};\nconsole.log(filter((i) => i === 5, tree))\n\n//Output\nBranch {\n    tag: 'branch',\n    left: Leaf { tag: 'leaf', value: 2 },\n    right:\n     Branch {\n       tag: 'branch',\n       left: undefined,\n       right: Leaf { tag: 'leaf', value: 4 } } \n       }\n```\n\n### Zip\n\nSignature->   zip: Tree<A> -> Tree<B> -> Tree<Array<A|B>> | undefined\n\ncreates a new tree out of two supplied trees by pairing up equally-positioned items from both trees.\nBoth trees should be of same structure otherwise it would be undefined\n\n```ts\nconst tree: Tree<number> = {\n    tag: 'branch',\n    left: { tag: 'leaf', value: 2 },\n    right: {\n        tag: 'branch',\n        left: { tag: 'leaf', value: 5 },\n        right: { tag: 'leaf', value: 4 },\n    },\n};\n\nconsole.log(JSON.stringify(zip(tree, tree), null, 2));\n\n// Output\n{\n  \"tag\": \"branch\",\n  \"left\": {\n    \"tag\": \"leaf\",\n    \"value\": [2,2]\n  },\n  \"right\": {\n    \"tag\": \"branch\",\n    \"left\": {\n      \"tag\": \"leaf\",\n      \"value\": [5,5]\n    },\n    \"right\": {\n      \"tag\": \"leaf\",\n      \"value\": [4,4]\n    }\n  }\n}\n```","readmeFilename":"README.md"}