{"_id":"@6pm/tuple","_rev":"3-ab2bdfd4db931c095364eee197ef19e5","name":"@6pm/tuple","description":"Immutable singleton tuple types","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@6pm/tuple","version":"1.0.0","author":{"name":"James Andrews","email":"jka6510@gmail.com"},"description":"Immutable singleton tuple types","keywords":["tuple","map","weakmap"],"scripts":{"test":"node ./node_modules/testem/testem.js -f test/testem.yml","cover":"istanbul cover ./node_modules/.bin/_mocha -- test/coverage.js","coveralls":"istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"},"main":"lib/tuple.js","engines":{"node":">=4"},"dependencies":{},"devDependencies":{"coveralls":"^2.11.6","istanbul":"^0.4.2","mocha":"^2.4.5","mocha-lcov-reporter":"^1.0.0","should":"^8.2.2","testem":"^1.2.2"},"directories":{"test":"test"},"repository":{"type":"git","url":"https://www.github.com/6pm-js/tuple.git"},"license":"MIT","gitHead":"632fe2554ce8d94f850cc8c91f138218a45e0ebd","_id":"@6pm/tuple@1.0.0","_shasum":"92c16f0492dc479aeb580ee0c9f66fe50a780250","_from":".","_npmVersion":"3.6.0","_nodeVersion":"5.6.0","_npmUser":{"name":"6pm","email":"jka6510@gmail.com"},"dist":{"shasum":"92c16f0492dc479aeb580ee0c9f66fe50a780250","tarball":"https://registry.npmjs.org/@6pm/tuple/-/tuple-1.0.0.tgz","integrity":"sha512-s13RbYatMuAcC1iu+V0hPW8WbAYGIWokcapY9AWnTkV64vBXmzBl9FHzQN/WEKf+2Zyd8PaMaBsjdzNhiLG0sw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCUngwU70R13OOiWt7Nsb/CxBYx7NxFvxmEiBnckvESlgIhAK3tLUs6I8sl1rHZeTYzqVCIFL/ipR3YkQbYoLIghN7p"}]},"maintainers":[{"name":"6pm","email":"jka6510@gmail.com"}],"_npmOperationalInternal":{"host":"packages-9-west.internal.npmjs.com","tmp":"tmp/tuple-1.0.0.tgz_1455495531417_0.007557005854323506"}}},"readme":"6pm Tuple\r\n---------\r\n\r\n[![Build Status](https://travis-ci.org/6pm-js/tuple.svg?branch=master)](https://travis-ci.org/6pm-js/tuple) [![Coverage Status](https://coveralls.io/repos/github/6pm-js/tuple/badge.svg?branch=master)](https://coveralls.io/github/6pm-js/tuple?branch=master)\r\n\r\nThe `@6pm/tuple` package implements tuples as immutable arrays of values, with\r\nthe additional guarantee that each combination of values is represented by a\r\nsingleton tuple instance.\r\n\r\nBecause of the singleton nature, these tuples are suitable for identity\r\ncomparison (`tuple1 === tuple2`), and storage in `Set` and `WeakSet`, and as\r\nkey values for `Map` and `WeakMap`.\r\n\r\n\r\n## Installing\r\n\r\n``` sh\r\nnpm install @6pm/tuple\r\n```\r\n\r\n\r\n## Running the test suite\r\n\r\nFrom within the `@6pm/tuple` package.\r\n\r\n- browser tests:\r\n\r\n``` sh\r\nnpm test\r\n```\r\n\r\nand follow the instructions provided\r\n\r\n- cli tests:\r\n\r\n``` sh\r\nnpm install -g mocha\r\nmocha\r\n```\r\n\r\n- ci tests\r\n\r\n``` sh\r\nnpm test ci\r\n```\r\n\r\n- coverage test\r\n\r\n``` sh\r\nnpm run cover\r\n```\r\n\r\n## Usage\r\n\r\nCreate a tuple by supplying an array of values via either:\r\n\r\n``` JavaScript\r\nTuple.for([ a, b, c ]);\r\n```\r\n\r\nor:\r\n\r\n``` JavaScript\r\nvar tuple = Tuple.any([ 1, null, Infinity ]);\r\n\r\nTuple.any([ 1, null, Infinity ]) === tuple; // true\r\n```\r\n\r\nTuples are rendered immutable, via `Object.freeze`, so any attempt to modify\r\ntheir members is silently ignored.\r\n\r\n``` JavaScript\r\nvar tuple = Tuple.any([ 1, 2, 3 ]);\r\ntuple[1] = -1;\r\n\r\ntuple[1]; // 2\r\n```\r\n\r\n\r\n### for or any?\r\n\r\nThe two methods differ, in that `any()` allows primitive values, whereas `for()`\r\nonly allows values eligible as `Map` keys, with the addition of `null` and\r\n`undefined`.  Primitive values come with a cost, though, so should be used with\r\ncaution!\r\n\r\nBoth methods share the same *tuple space*, for example:\r\n\r\n``` JavaScript\r\nvar a = {}, b = {};\r\n\r\nTuple.for([ a, b ]) === Tuple.any([ a, b ]); // true\r\n```\r\n\r\n\r\n### any\r\n\r\nThe reason for this schism is that there is currently no generic mechanism to\r\nallow a weak reference to a value within JavaScript (only by key, via WeakMap),\r\nso usage of `any()` comes with a cost - every distinct primitive value used in a\r\ntuple will use memory, that cannot be reclaimed by the garbage collector.\r\n\r\nThis means that `any()` should be used cautiously, typically when the set of\r\nprimitives that may be supplied is bounded and relatively small, otherwise this\r\nopens the potential for memory leakage.\r\n\r\n\r\n### for\r\n\r\nUsing `for()` does not leak memory, if any of the elements of the resultant\r\ntuple become eligible for garbage collection, then the tuple itself becomes\r\nunreachable, and it too will eventually be garbage collected, once no direct\r\nreferences exist.\r\n","maintainers":[{"name":"6pm","email":"jka6510@gmail.com"}],"time":{"modified":"2022-06-12T14:11:54.201Z","created":"2016-02-15T00:18:55.311Z","1.0.0":"2016-02-15T00:18:55.311Z"},"keywords":["tuple","map","weakmap"],"repository":{"type":"git","url":"https://www.github.com/6pm-js/tuple.git"},"author":{"name":"James Andrews","email":"jka6510@gmail.com"},"license":"MIT","readmeFilename":"README.md"}