{ "info": { "author": "halprin", "author_email": "me@halprin.io", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# iterator-chain\nChain together lazily computed modifications to iterators.\n\nOne normally needs to do the following\n```python\nlist(map(lambda element: element / 3,\nfilter(lambda element: element > 32,\nmap(lambda element: element * 2, [5, 78, 12, 26]))))\n```\n\nInstead do this\n```python\niterator_chain.from_iterable([5, 78, 12, 26]) \\\n.map(lambda element: element * 2) \\\n.filter(lambda element: element > 32) \\\n.map(lambda element: element / 3).list()\n```\n\nIt allows the developer to read the code in a more natural fashion: from left to right and from top to bottom. The\ndeveloper no longer needs to \"unwrap\" the functions to understand the logic.\n\n## Install\nInclude `iterator-chain` in your `requirements.txt` file and/or use `pip` to install it.\n```bash\n$ pip install iterator-chain\n```\n\n## API\nStart by importing the package.\n```python\nimport iterator_chain\n```\n\n### Start the chain\nTo start the chain, use the `from_iterable` or `from_iterable_parallel` function. They take an iterable.\n```python\nan_iterable = [5, 78, 12, 26]\nchain = iterator_chain.from_iterable(an_iterable)\nparallel_chain = iterator_chain.from_iterable_parallel(an_iterable)\n```\n\n| Function | Arguments | Description |\n| --- | --- | --- |\n| `from_iterable` | \u2022 `iterable` - An iterable to be used in the iterator chain | Starts the iterator chain with the supplied iterable. Chaining and terminating methods can now be called on the result. |\n| `from_iterable_parallel` | \u2022 `iterable` - An iterable to be used in the iterator chain
\u2022 `chunksize` - Keyword. How big of chunks to split the iterator up across the parallel execution units. If unspecified or None, the chunk size will start at 1 and send that many elements to each execution unit. The chunk size will then increment in powers of two and send that many items to each execution unit. This is repeated until the iterator is exhausted. This value is used as the default chunksize for all the following parallel based methods. A specific parallel based method's chunksize can be overrided by supplying the `chunksize` keyword to that method. | Starts the iterator chain with the supplied iterable. Chaining and terminating methods can now be called on the result. Certain chaining and terminating methods will occur in parallel. Parallel means separate processes to get around Python's GIL. |\n\n\n### Continuing the chain\nFrom there, one can call a plethora of additional methods to modify the iterable passed in originally. The methods are\noutlined below. The methods fall into one of two categories: chaining or terminating.\n\n- Chaining methods apply some modification to the elements in the iterator, but keeps the chain alive.\nThis allows additional chaining methods to be subsequently called on the result.\nBecause modifications are lazily computed, none of the modifications from chaining methods are applied until _after_ a terminating method is\ncalled.\n- Terminating methods also apply some modification, requests some information, or executes something on the elements in the iterator. They stop the chaining by returning\nan actual value. This value will depend on all the previous chaining methods being executed first.\n\n#### Chaining methods\n| Method | Arguments | Description |\n| --- | --- | --- |\n| `map` | \u2022 `function` - A function that takes a single argument | Will run the `function` across all the elements in the iterator. |\n| `filter` | \u2022 `function` - A function that takes a single argument | Will run the `function` on every element. `function` should return a truthy or falsy value. On true, the element will stay; on false, the element will be removed. |\n| `skip` | \u2022 `number` - An integer | The `number` number of elements will be skipped over and effectively removed. |\n| `distinct` | | Any duplicates will be removed. |\n| `limit` | \u2022 `max_size` - An integer | The iterator will stop after `max_size` elements. Any elements afterward are effectively removed. |\n| `flatten` | | Any element that is an iterable itself will have its elements iterated over first before continuing with the remaining elements. Strings (`str`) do not count as an iterable for this method. Dictionaries flatten to its item tuples. |\n| `sort` | \u2022 `key` - Keyword. A function of one argument that is used to extract a comparison key from each element
\u2022 `cmp` - Keyword. A Python 2.x \"cmp\" function that takes two arguments
\u2022 `reverse` - Keyword. If set to `True`, the elements will be sorted in the reverse order | Sorts the iterator based on the elements' values. Use `key` or `cmp` to make a custom comparison. If `key` is specified, `cmp` cannot be used. This method is expensive because it must serialize all the values into a sequence. |\n| `reverse` | | Reverses the iterator. The last item will be first, and the first item will be last. This method is expensive because it must serialize all the values into a list. |\n\n##### Parallel Versions\n| Method | Arguments | Description |\n| --- | --- | --- |\n| `map` | \u2022 `function` - A function that takes a single argument
\u2022 `chunksize` - Keyword. Overrides the chunksize supplied to the original `from_iterable_parallel` | Will run the `function` across all the elements in the iterator in parallel. |\n| `filter` | \u2022 `function` - A function that takes a single argument
\u2022 `chunksize` - Keyword. Overrides the chunksize supplied to the original `from_iterable_parallel` | Will run the `function` on every element in parallel. `function` should return a truthy or falsy value. On true, the element will stay; on false, the element will be removed. |\n\n#### Terminating methods\n| Method | Arguments | Description |\n| --- | --- | --- |\n| `list` | | Serializes the iterator chain into a `list` and returns it. |\n| `count` | | Returns the number of elements in the iterator. |\n| `first` | \u2022 `default` - Keyword. Any value. | Returns just the first item in the iterator. If the iterator is empty, the `default` is returned. |\n| `last` | \u2022 `default` - Keyword. Any value. | Returns just the last item in the iterator. If the iterator is empty, the `default` is returned. |\n| `max` | \u2022 `default` - Keyword. Any value. | Returns the largest valued element in the iterator. If the iterator is empty, the `default` is returned. |\n| `min` | \u2022 `default` - Keyword. Any value. | Returns the smallest valued element in the iterator. If the iterator is empty, the `default` is returned. |\n| `sum` | \u2022 `default` - Keyword. Any value. | Sums all the elements in the iterator together. If any of the elements are un-summable, the `default` is returned. |\n| `reduce` | \u2022 `function` - A function that takes two arguments
\u2022 `initial` - Keyword. Any value. | Applies the function to two elements in the iterator cumulatively. Subsequent calls to `function` uses the previous return value from `function` as the first argument and the next element in the iterator as the second argument. The final value is returned. If `initial` is present, it is placed before the items of the sequence in the calculation, and serves as a default when the sequence is empty. |\n| `for_each` | \u2022 `function` - A function that takes one argument and returns nothing | Executes `function` on every element in the iterator. There is no return value. If you are wanting to return a list of values based on the function, use `.map(_function_).list()`. |\n| `all_match` | \u2022 `function` - A function that takes one argument and returns a boolean | Returns `True` only if _all_ the elements return `True` after applying the `function` to them. Else returns `False`. |\n| `any_match` | \u2022 `function` - A function that takes one argument and returns a boolean | Returns `True` if just one element return `True` after applying the `function` to it. If all elements result in `False`, `False` is returned. |\n| `none_match` | \u2022 `function` - A function that takes one argument and returns a boolean | Returns `True` only if _all_ the elements return `False` after applying the `function` to them. Else returns `True`. |\n\n##### Parallel Versions\n| Method | Arguments | Description |\n| --- | --- | --- |\n| `for_each` | \u2022 `function` - A function that takes one argument and returns nothing
\u2022 `chunksize` - Keyword. Overrides the chunksize supplied to the original `from_iterable_parallel` | Executes `function` on every element in the iterator in parallel. There is no return value. If you are wanting to return a list of values based on the function, use `.map(function).list()`. |\n\n## Examples\n```python\nimport iterator_chain\nan_iterable = [5, 78, 12, 26]\niterator_chain.from_iterable(an_iterable) \\ #starts the chain\n .map(lambda element: element * 2) \\ #multiplies every element by two: [10, 156, 24, 52]\n .filter(lambda element: element > 32) \\ #keeps any element greater than 32: [156, 52]\n .map(lambda element: element / 3) \\ #divides every element by three: [52.0, 17.333333333333332]\n .list() #and finally returns a list of the result for later use in your application: [52.0, 17.333333333333332]\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/halprin/iterator-chain", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "iterator-chain", "package_url": "https://pypi.org/project/iterator-chain/", "platform": "", "project_url": "https://pypi.org/project/iterator-chain/", "project_urls": { "Homepage": "https://github.com/halprin/iterator-chain" }, "release_url": "https://pypi.org/project/iterator-chain/1.1.0/", "requires_dist": null, "requires_python": "", "summary": "Chain together lazily computed modifications to iterators", "version": "1.1.0" }, "last_serial": 5974704, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "8a0bde5e5b8bf9a181a6230ea0e78091", "sha256": "7021896bc4fa7f5942292f1ac6528c9a7377a7673af1c0bf84483fae9f97d4c2" }, "downloads": -1, "filename": "iterator_chain-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "8a0bde5e5b8bf9a181a6230ea0e78091", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 16950, "upload_time": "2019-06-14T04:26:20", "url": "https://files.pythonhosted.org/packages/51/b5/4bb83caff6b2ad713b9959abd8edee3a2519e5c7aaa2b74798385aa040a0/iterator_chain-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5540073418fc02e4bdb2bcfec17495bf", "sha256": "8fbdb77769991eb344e89d859467f01c9d74562dc235da81e8dac7e26dc9076e" }, "downloads": -1, "filename": "iterator-chain-1.0.0.tar.gz", "has_sig": false, "md5_digest": "5540073418fc02e4bdb2bcfec17495bf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4171, "upload_time": "2019-06-14T04:26:22", "url": "https://files.pythonhosted.org/packages/c7/4e/5189dca721afd9423ddb4c676712a88da10213f36d1d0b67fdc16aff4426/iterator-chain-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "5fc62a9611234174bc6a49e6e23286c0", "sha256": "3a8c960c3b4e193138e7da24136408e52d3cdd7b2c202392feb8cd6062287ecc" }, "downloads": -1, "filename": "iterator_chain-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "5fc62a9611234174bc6a49e6e23286c0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10259, "upload_time": "2019-10-15T04:17:06", "url": "https://files.pythonhosted.org/packages/f2/38/f23ef3da1f6f6b4b34ca00dbdbb0545ec5a67e3c6f4612b9c3a27d81d4cb/iterator_chain-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7e7ede33ba2c0f5ae9d01c0909da2054", "sha256": "c1ca0fe2ab568c162098560ccd6a43893eec3048a1b61230ad56dfd6ac03e024" }, "downloads": -1, "filename": "iterator-chain-1.1.0.tar.gz", "has_sig": false, "md5_digest": "7e7ede33ba2c0f5ae9d01c0909da2054", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8548, "upload_time": "2019-10-15T04:17:07", "url": "https://files.pythonhosted.org/packages/90/69/27e9fc79ec697724de680acae9738badce289078fb15b7cc0afe9bc6b055/iterator-chain-1.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5fc62a9611234174bc6a49e6e23286c0", "sha256": "3a8c960c3b4e193138e7da24136408e52d3cdd7b2c202392feb8cd6062287ecc" }, "downloads": -1, "filename": "iterator_chain-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "5fc62a9611234174bc6a49e6e23286c0", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10259, "upload_time": "2019-10-15T04:17:06", "url": "https://files.pythonhosted.org/packages/f2/38/f23ef3da1f6f6b4b34ca00dbdbb0545ec5a67e3c6f4612b9c3a27d81d4cb/iterator_chain-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7e7ede33ba2c0f5ae9d01c0909da2054", "sha256": "c1ca0fe2ab568c162098560ccd6a43893eec3048a1b61230ad56dfd6ac03e024" }, "downloads": -1, "filename": "iterator-chain-1.1.0.tar.gz", "has_sig": false, "md5_digest": "7e7ede33ba2c0f5ae9d01c0909da2054", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8548, "upload_time": "2019-10-15T04:17:07", "url": "https://files.pythonhosted.org/packages/90/69/27e9fc79ec697724de680acae9738badce289078fb15b7cc0afe9bc6b055/iterator-chain-1.1.0.tar.gz" } ] }