IterFun
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:
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.
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
invertis_evenis_oddis_primemiller_rabinsign
Iter
allanyatavgcartesianchunk_bychunk_everychunk_whilecombinationscombinations_with_replacementcountcount_untildedupdedup_bydifferencedropdrop_everydrop_whileduplicatesfilterfindfind_indexfind_valueflat_mapflat_mapflat_map_reduceflattenfrequenciesgroup_byintersectsintersperseintois_disjointis_emptyis_memberis_subsetis_supersetjoinlinspacemapmap_everymap_interspersemap_joinmap_reducemaxminmin_maxopenpermutationsproductrandintrandomrangereducereduce_whilerejectreversereverse_slicesavescanshortenshufflesliceslidesortsplitsplit_whilesplit_withsumsymmetric_differencetaketake_everytake_randomtake_whileto_dictto_listtransposeunionuniqueunzipwith_indexzip_reducezip_with
Authors
| Name | Mail Address | GitHub Profile |
|---|---|---|
| Stefan Greve | greve.stefan@outlook.jp | StefanGreve |
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE file for more details.
Release files for iterfun 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| iterfun-0.0.5.tar.gz | 23.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| iterfun-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 42.1 kB
Release files / iterfun-0.0.5.tar.gz
| Download URL | iterfun-0.0.5.tar.gz |
|---|---|
| Size | 23.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e18f48596d406f090c4ee6436ae1b5e4ee493fb3c9b554b649cf7fcd7a3a114
|
|
BLAKE2b-256 checksum How to use checksums |
01f40434e0b82d546aba3a1ab63113556111a0fe8abc17f73176aa1975b7d94b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Release files / iterfun-0.0.5-py3-none-any.whl
| Download URL | iterfun-0.0.5-py3-none-any.whl |
|---|---|
| Size | 18.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
afe17ac0c65d04b71b1ef36184ad7988b9aa8048a5a76a00bda7bb5404291334
|
|
BLAKE2b-256 checksum How to use checksums |
fb6cb5a1bf9d72ea64fdefbf3cb4df7f5557be2cef47ee40478b795c18ed7d99
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|