iterfun


Nameiterfun JSON
Version 0.0.5 PyPI version JSON
download
home_pagehttps://github.com/StefanGreve/iterfun
SummaryImplements an eager iterator class reminiscent of Elixir's Enum structure.
upload_time2023-01-29 13:39:46
maintainer
docs_urlNone
authorStefanGreve
requires_python>=3.8
licenseMIT
keywords utils functional programming functools itertools extension
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <a title="Project Logo">
    <img height="150" style="margin-top:15px" src="https://github.com/StefanGreve/iterfun/blob/master/iterfun.svg">
  </a>
</p>

<h1 align="center">IterFun</h1>

<p align="center">
    <a href="https://github.com/StefanGreve/iterfun/actions?query=workflow%3ACI" title="Continuous Integration" target="_blank">
        <img src="https://github.com/StefanGreve/iterfun/actions/workflows/python-app.yml/badge.svg">
    </a>
    <a href="https://github.com/StefanGreve/iterfun" title="Release Version">
        <img src="https://img.shields.io/pypi/v/iterfun?color=blue&label=Release">
    </a>
    <a title="Supported Python Versions">
        <img src="https://img.shields.io/pypi/pyversions/iterfun">
    </a>
    <a href="https://www.gnu.org/licenses/gpl-3.0.en.html" title="License Information" target="_blank" rel="noopener noreferrer">
        <img src="https://img.shields.io/badge/License-MIT-blue.svg">
    </a>
    <a title="Downloads per Month">
        <img src="https://img.shields.io/pypi/dm/iterfun">
    </a>
</p>

## About

IterFun implements an eager iterator class reminiscent of Elixir's `Enum` structure
that features a series of handy methods for performing common data transformations.

It's a continuously evolving project specifically developed to meet my personal
needs, but I have decided to put it out in the open in case someone else find it
as useful as me. Contributions in form of pull requests or suggestions are always
welcome. If you need a more mature library for your project, consider one of these
alternatives instead:

- [`toolz`](https://github.com/pytoolz/toolz)
- [`fn.py`](https://github.com/kachayev/fn.py)
- [`more-itertools`](https://github.com/more-itertools/more-itertools)
- [`Pipe`](https://github.com/JulienPalard/Pipe)

---

## Examples

### Two Sum Problem

Given an array of integers `domain` and an integer `target`, return indices of the
two numbers such that they add up to target. You may assume that each input would
have exactly one solution, and you may not use the same element twice. You can
return the answer in any order.

```python
from iterfun import Iter

target = 12
domain = [45, 26, 5, 41, 58, 97, 82, 9, 79, 22, 3, 74, 70, 84, 17, 79, 41, 96, 13, 89]

pair = Iter(domain) \
    .filter(lambda x: x < target) \
    .combinations(2) \
    .filter(lambda x: sum(x) == target) \
    .flatten() \
    .to_list()

# [7, 10]
print(Iter(domain).find_index(lambda x: x in pair).image)
```

---

## Technical Limitations

For reasons of simplicity, the mutable state in `image` is exposed as a list or
dictionary and not as a generator which is capable of dealing with very large
sequences. It's an implementation detail that is necessary for some index-based methods,
though this behavior might change in future versions of this library where applicable.

There is probably room to improve the overall performance and accuracy of this library.
To this end, future updates will also increase the test coverage in order to consider
more edge cases and method interoperability. Notice that the terms and conditions
of the MIT License will always apply.

## Method Reference

This method reference serves as a first point of contact to help you discover
what this library is capable of. Documentation and small, self-contained examples
are provided in the doc strings of each method that you can read in the privacy of
your code editor of choice.

### Functions

- `invert`
- `is_even`
- `is_odd`
- `is_prime`
- `miller_rabin`
- `sign`

### Iter

- `all`
- `any`
- `at`
- `avg`
- `cartesian`
- `chunk_by`
- `chunk_every`
- `chunk_while`
- `combinations`
- `combinations_with_replacement`
- `count`
- `count_until`
- `dedup`
- `dedup_by`
- `difference`
- `drop`
- `drop_every`
- `drop_while`
- `duplicates`
- `filter`
- `find`
- `find_index`
- `find_value`
- `flat_map`
- `flat_map`
- `flat_map_reduce`
- `flatten`
- `frequencies`
- `group_by`
- `intersects`
- `intersperse`
- `into`
- `is_disjoint`
- `is_empty`
- `is_member`
- `is_subset`
- `is_superset`
- `join`
- `linspace`
- `map`
- `map_every`
- `map_intersperse`
- `map_join`
- `map_reduce`
- `max`
- `min`
- `min_max`
- `open`
- `permutations`
- `product`
- `randint`
- `random`
- `range`
- `reduce`
- `reduce_while`
- `reject`
- `reverse`
- `reverse_slice`
- `save`
- `scan`
- `shorten`
- `shuffle`
- `slice`
- `slide`
- `sort`
- `split`
- `split_while`
- `split_with`
- `sum`
- `symmetric_difference`
- `take`
- `take_every`
- `take_random`
- `take_while`
- `to_dict`
- `to_list`
- `transpose`
- `union`
- `unique`
- `unzip`
- `with_index`
- `zip_reduce`
- `zip_with`

---

## Authors

| Name             | Mail Address            | GitHub Profile                                |
|------------------|-------------------------|-----------------------------------------------|
| Stefan Greve     | greve.stefan@outlook.jp | [StefanGreve](https://github.com/StefanGreve) |

See also the list of [contributors](https://github.com/stefangreve/iterfun/contributors)
who participated in this project.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
for more details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/StefanGreve/iterfun",
    "name": "iterfun",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "utils,functional programming,functools,itertools,extension",
    "author": "StefanGreve",
    "author_email": "greve.stefan@outlook.jp",
    "download_url": "https://files.pythonhosted.org/packages/01/f4/0434e0b82d546aba3a1ab63113556111a0fe8abc17f73176aa1975b7d94b/iterfun-0.0.5.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\r\n  <a title=\"Project Logo\">\r\n    <img height=\"150\" style=\"margin-top:15px\" src=\"https://github.com/StefanGreve/iterfun/blob/master/iterfun.svg\">\r\n  </a>\r\n</p>\r\n\r\n<h1 align=\"center\">IterFun</h1>\r\n\r\n<p align=\"center\">\r\n    <a href=\"https://github.com/StefanGreve/iterfun/actions?query=workflow%3ACI\" title=\"Continuous Integration\" target=\"_blank\">\r\n        <img src=\"https://github.com/StefanGreve/iterfun/actions/workflows/python-app.yml/badge.svg\">\r\n    </a>\r\n    <a href=\"https://github.com/StefanGreve/iterfun\" title=\"Release Version\">\r\n        <img src=\"https://img.shields.io/pypi/v/iterfun?color=blue&label=Release\">\r\n    </a>\r\n    <a title=\"Supported Python Versions\">\r\n        <img src=\"https://img.shields.io/pypi/pyversions/iterfun\">\r\n    </a>\r\n    <a href=\"https://www.gnu.org/licenses/gpl-3.0.en.html\" title=\"License Information\" target=\"_blank\" rel=\"noopener noreferrer\">\r\n        <img src=\"https://img.shields.io/badge/License-MIT-blue.svg\">\r\n    </a>\r\n    <a title=\"Downloads per Month\">\r\n        <img src=\"https://img.shields.io/pypi/dm/iterfun\">\r\n    </a>\r\n</p>\r\n\r\n## About\r\n\r\nIterFun implements an eager iterator class reminiscent of Elixir's `Enum` structure\r\nthat features a series of handy methods for performing common data transformations.\r\n\r\nIt's a continuously evolving project specifically developed to meet my personal\r\nneeds, but I have decided to put it out in the open in case someone else find it\r\nas useful as me. Contributions in form of pull requests or suggestions are always\r\nwelcome. If you need a more mature library for your project, consider one of these\r\nalternatives instead:\r\n\r\n- [`toolz`](https://github.com/pytoolz/toolz)\r\n- [`fn.py`](https://github.com/kachayev/fn.py)\r\n- [`more-itertools`](https://github.com/more-itertools/more-itertools)\r\n- [`Pipe`](https://github.com/JulienPalard/Pipe)\r\n\r\n---\r\n\r\n## Examples\r\n\r\n### Two Sum Problem\r\n\r\nGiven an array of integers `domain` and an integer `target`, return indices of the\r\ntwo numbers such that they add up to target. You may assume that each input would\r\nhave exactly one solution, and you may not use the same element twice. You can\r\nreturn the answer in any order.\r\n\r\n```python\r\nfrom iterfun import Iter\r\n\r\ntarget = 12\r\ndomain = [45, 26, 5, 41, 58, 97, 82, 9, 79, 22, 3, 74, 70, 84, 17, 79, 41, 96, 13, 89]\r\n\r\npair = Iter(domain) \\\r\n    .filter(lambda x: x < target) \\\r\n    .combinations(2) \\\r\n    .filter(lambda x: sum(x) == target) \\\r\n    .flatten() \\\r\n    .to_list()\r\n\r\n# [7, 10]\r\nprint(Iter(domain).find_index(lambda x: x in pair).image)\r\n```\r\n\r\n---\r\n\r\n## Technical Limitations\r\n\r\nFor reasons of simplicity, the mutable state in `image` is exposed as a list or\r\ndictionary and not as a generator which is capable of dealing with very large\r\nsequences. It's an implementation detail that is necessary for some index-based methods,\r\nthough this behavior might change in future versions of this library where applicable.\r\n\r\nThere is probably room to improve the overall performance and accuracy of this library.\r\nTo this end, future updates will also increase the test coverage in order to consider\r\nmore edge cases and method interoperability. Notice that the terms and conditions\r\nof the MIT License will always apply.\r\n\r\n## Method Reference\r\n\r\nThis method reference serves as a first point of contact to help you discover\r\nwhat this library is capable of. Documentation and small, self-contained examples\r\nare provided in the doc strings of each method that you can read in the privacy of\r\nyour code editor of choice.\r\n\r\n### Functions\r\n\r\n- `invert`\r\n- `is_even`\r\n- `is_odd`\r\n- `is_prime`\r\n- `miller_rabin`\r\n- `sign`\r\n\r\n### Iter\r\n\r\n- `all`\r\n- `any`\r\n- `at`\r\n- `avg`\r\n- `cartesian`\r\n- `chunk_by`\r\n- `chunk_every`\r\n- `chunk_while`\r\n- `combinations`\r\n- `combinations_with_replacement`\r\n- `count`\r\n- `count_until`\r\n- `dedup`\r\n- `dedup_by`\r\n- `difference`\r\n- `drop`\r\n- `drop_every`\r\n- `drop_while`\r\n- `duplicates`\r\n- `filter`\r\n- `find`\r\n- `find_index`\r\n- `find_value`\r\n- `flat_map`\r\n- `flat_map`\r\n- `flat_map_reduce`\r\n- `flatten`\r\n- `frequencies`\r\n- `group_by`\r\n- `intersects`\r\n- `intersperse`\r\n- `into`\r\n- `is_disjoint`\r\n- `is_empty`\r\n- `is_member`\r\n- `is_subset`\r\n- `is_superset`\r\n- `join`\r\n- `linspace`\r\n- `map`\r\n- `map_every`\r\n- `map_intersperse`\r\n- `map_join`\r\n- `map_reduce`\r\n- `max`\r\n- `min`\r\n- `min_max`\r\n- `open`\r\n- `permutations`\r\n- `product`\r\n- `randint`\r\n- `random`\r\n- `range`\r\n- `reduce`\r\n- `reduce_while`\r\n- `reject`\r\n- `reverse`\r\n- `reverse_slice`\r\n- `save`\r\n- `scan`\r\n- `shorten`\r\n- `shuffle`\r\n- `slice`\r\n- `slide`\r\n- `sort`\r\n- `split`\r\n- `split_while`\r\n- `split_with`\r\n- `sum`\r\n- `symmetric_difference`\r\n- `take`\r\n- `take_every`\r\n- `take_random`\r\n- `take_while`\r\n- `to_dict`\r\n- `to_list`\r\n- `transpose`\r\n- `union`\r\n- `unique`\r\n- `unzip`\r\n- `with_index`\r\n- `zip_reduce`\r\n- `zip_with`\r\n\r\n---\r\n\r\n## Authors\r\n\r\n| Name             | Mail Address            | GitHub Profile                                |\r\n|------------------|-------------------------|-----------------------------------------------|\r\n| Stefan Greve     | greve.stefan@outlook.jp | [StefanGreve](https://github.com/StefanGreve) |\r\n\r\nSee also the list of [contributors](https://github.com/stefangreve/iterfun/contributors)\r\nwho participated in this project.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file\r\nfor more details.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Implements an eager iterator class reminiscent of Elixir's Enum structure.",
    "version": "0.0.5",
    "split_keywords": [
        "utils",
        "functional programming",
        "functools",
        "itertools",
        "extension"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fb6cb5a1bf9d72ea64fdefbf3cb4df7f5557be2cef47ee40478b795c18ed7d99",
                "md5": "50b1d9c720057dbb90cd04bc4e86b032",
                "sha256": "afe17ac0c65d04b71b1ef36184ad7988b9aa8048a5a76a00bda7bb5404291334"
            },
            "downloads": -1,
            "filename": "iterfun-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "50b1d9c720057dbb90cd04bc4e86b032",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 18881,
            "upload_time": "2023-01-29T13:39:44",
            "upload_time_iso_8601": "2023-01-29T13:39:44.843332Z",
            "url": "https://files.pythonhosted.org/packages/fb/6c/b5a1bf9d72ea64fdefbf3cb4df7f5557be2cef47ee40478b795c18ed7d99/iterfun-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "01f40434e0b82d546aba3a1ab63113556111a0fe8abc17f73176aa1975b7d94b",
                "md5": "ae21bf2e0609e93bbd426c3cbbb6cd06",
                "sha256": "6e18f48596d406f090c4ee6436ae1b5e4ee493fb3c9b554b649cf7fcd7a3a114"
            },
            "downloads": -1,
            "filename": "iterfun-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "ae21bf2e0609e93bbd426c3cbbb6cd06",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 23211,
            "upload_time": "2023-01-29T13:39:46",
            "upload_time_iso_8601": "2023-01-29T13:39:46.442803Z",
            "url": "https://files.pythonhosted.org/packages/01/f4/0434e0b82d546aba3a1ab63113556111a0fe8abc17f73176aa1975b7d94b/iterfun-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-29 13:39:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "StefanGreve",
    "github_project": "iterfun",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "iterfun"
}
        
Elapsed time: 0.03275s