{"_id":"pop-iterate","_rev":"40750","name":"pop-iterate","description":"A polymorphic iterate operator for arrays and other iterables","dist-tags":{"latest":"1.0.1"},"maintainers":[{"name":"kriskowal","email":""}],"time":{"modified":"2021-06-03T10:12:18.000Z","created":"2015-01-29T07:05:25.709Z","1.0.1":"2015-01-31T07:50:58.383Z","1.0.0":"2015-01-29T07:05:25.709Z"},"users":{},"author":{"name":"Kris Kowal","email":"kris@cixar.com"},"repository":{"type":"git","url":"https://github.com/kriskowal/pop-iterate.git"},"versions":{"1.0.1":{"name":"pop-iterate","version":"1.0.1","description":"A polymorphic iterate operator for arrays and other iterables","main":"pop-iterate.js","directories":{"test":"test"},"devDependencies":{"jasminum":"^2.0.5"},"scripts":{"test":"jasminum test"},"repository":{"type":"git","url":"https://github.com/kriskowal/pop-iterate.git"},"keywords":["pop","polymorphic","operator","iterate"],"author":{"name":"Kris Kowal","email":"kris@cixar.com"},"license":"MIT","bugs":{"url":"https://github.com/kriskowal/pop-iterate/issues"},"homepage":"https://github.com/kriskowal/pop-iterate","gitHead":"dc8f214537d6134d25a6da84ca78715bfbcd0001","_id":"pop-iterate@1.0.1","_shasum":"ceacfdab4abf353d7a0f2aaa2c1fc7b3f9413ba3","_from":".","_npmVersion":"1.4.21","_npmUser":{"name":"kriskowal","email":"kris.kowal@cixar.com"},"maintainers":[{"name":"kriskowal","email":""}],"dist":{"shasum":"ceacfdab4abf353d7a0f2aaa2c1fc7b3f9413ba3","size":2665,"noattachment":false,"key":"/pop-iterate/-/pop-iterate-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/pop-iterate/download/pop-iterate-1.0.1.tgz"},"publish_time":1422690658383,"_cnpm_publish_time":1422690658383,"_hasShrinkwrap":false},"1.0.0":{"name":"pop-iterate","version":"1.0.0","description":"A polymorphic iterate operator for arrays and other iterables","main":"pop-iterate.js","directories":{"test":"test"},"dependencies":{"jasminum":"^0.0.4"},"devDependencies":{},"scripts":{"test":"jasminum test"},"repository":{"type":"git","url":"https://github.com/kriskowal/pop-iterate.git"},"keywords":["pop","polymorphic","operator","iterate"],"author":{"name":"Kris Kowal","email":"kris@cixar.com"},"license":"MIT","bugs":{"url":"https://github.com/kriskowal/pop-iterate/issues"},"homepage":"https://github.com/kriskowal/pop-iterate","gitHead":"c6d803efd8e5957e00712ffbb422bf3a71560bce","_id":"pop-iterate@1.0.0","_shasum":"7cf01c43f91222759924fd93d114af3ca682aab1","_from":".","_npmVersion":"1.4.21","_npmUser":{"name":"kriskowal","email":"kris.kowal@cixar.com"},"maintainers":[{"name":"kriskowal","email":""}],"dist":{"shasum":"7cf01c43f91222759924fd93d114af3ca682aab1","size":2666,"noattachment":false,"key":"/pop-iterate/-/pop-iterate-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/pop-iterate/download/pop-iterate-1.0.0.tgz"},"publish_time":1422515125709,"_cnpm_publish_time":1422515125709,"_hasShrinkwrap":false}},"readme":"\n# Iterate\n\nThis JavaScript package exports an iterator operator that accepts arrays and any\nobject that implements iterate.\n\n```\n$ npm install --save pop-iterate\n```\n\nThe iterate operator accepts an array, or object that implements iterate, and\nreturns an iterator, as described by the [iterator protocol][Iterator], with\nsome extensions.\nThe iterations have an index property with the index corresponding to the value.\n\n[Iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/The_Iterator_protocol\n\n```js\nvar iterator = iterate([1, 2, 3]);\nexpect(iterator.next()).toEqual({value: 1, done: false, index: 0});\nexpect(iterator.next()).toEqual({value: 2, done: false, index: 1});\nexpect(iterator.next()).toEqual({value: 3, done: false, index: 2});\nexpect(iterator.next()).toEqual({done: true});\n```\n\nIterating on an array, the iterate method accepts optional start, stop, and step\narguments.\n\n```js\nvar array = [1, 2, 3, 4, 5, 6, 7, 8];\nvar iterator = iterate(array, 1, 6, 2);\nexpect(iterator.next()).toEqual({value: 2, done: false, index: 1});\nexpect(iterator.next()).toEqual({value: 4, done: false, index: 3});\nexpect(iterator.next()).toEqual({value: 6, done: false, index: 5});\nexpect(iterator.next()).toEqual({done: true});\n```\n\nThe iterate operator also iterates the owned properties of an object.\n\n```js\nvar object = {a: 10, b: 20, c: 30};\nvar iterator = iterate(object);\nexpect(iterator.next()).toEqual({value: 10, done: false, index: \"a\"});\nexpect(iterator.next()).toEqual({value: 20, done: false, index: \"b\"});\nexpect(iterator.next()).toEqual({value: 30, done: false, index: \"c\"});\nexpect(iterator.next()).toEqual({done: true});\n```\n\n## Polymorphic operator\n\nA well-planned system of objects is beautiful: a system where every meaningful\nmethod for an object has been anticipated in the design.\nInevitably, another layer of architecture introduces a new concept and with it\nthe temptation to monkey-patch, dunk-punch, or otherwise cover-up the omission.\nBut reaching backward in time, up through the layers of architecture doesn't\nalways compose well, when different levels introduce concepts of the same name\nbut distinct behavior.\n\nA polymorphic operator is a function that accepts as its first argument an\nobject and varies its behavior depending on its type.\nSuch an operator has the benefit of covering for the types from higher layers of\narchitecture, but defers to the eponymous method name of types yet to be\ndefined.\n\nThe iterate operator works for arrays and objects.\nAny other object can be iterable by implementing the `iterate` method, and the\niterate operator will defer to it.\n\n```js\nfunction Collection() {}\nCollection.prototype.iterate = function (start, stop, step) {\n};\n```\n\nThis package also exports the individual parts form which it makes iterators.\n\n```js\nvar Iteration = require(\"pop-iterate/iteration\");\nvar ArrayIterator = require(\"pop-iterate/array-iterator\");\nvar ObjectIterator = require(\"pop-iterate/object-iterator\");\n```\n\n","_attachments":{},"homepage":"https://github.com/kriskowal/pop-iterate","bugs":{"url":"https://github.com/kriskowal/pop-iterate/issues"},"license":"MIT"}