Provides models for convenient and efficient iteration
Project description
Iter Model
Description
Iter Model uses a method approach instead of individual functions to work with iterable objects.
Native approach
result = list(map(
lambda x: x ** 2,
filter(lambda x: x % 2 == 0, range(10)),
))
Iter Model approach
from iter_model import SyncIter
result = (
SyncIter(range(10))
.where(lambda x: x % 2 == 0)
.map(lambda x: x ** 2)
.to_list()
)
Generators
You can decorate your generator function and get SyncIter as a result
from iter_model import sync_iter
@sync_iter
def some_generator():
for item in range(10):
yield item
result = some_generator().take_while(lambda x: x < 5).to_list()
Async support
Iter Model also support async iterable and async function as condition.
import asyncio
from iter_model import async_iter
@async_iter
async def some_generator():
for item in range(10):
yield item
async def condition_a(x):
"""Some async condition"""
return x % 2 == 0
def condition_b(x):
"""Some sync condition"""
return x > 5
async def main():
result = await (
some_generator()
.where(condition_a)
.take_while(condition_b)
.to_list()
)
print(result)
asyncio.run(main())
SyncIter/AsyncIter provide the following methods
to_list()
to_tuple()
to_set()
enumerate()
take()
map()
skip()
skip_while()
count()
first_where()
where()
take_while()
first()
last()
chain()
all()
any()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
iter_model-0.2.0.tar.gz
(5.1 kB
view hashes)
Built Distribution
Close
Hashes for iter_model-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47980702951fcbcd5eaac75fe6f323fe6ee25e8e19ceafea4e42990b18232cd0 |
|
MD5 | 70624df6f01b017c515c66923d8291d6 |
|
BLAKE2b-256 | b4c1ec7b020d2565fdca72a8818dbce832b9bfb62611c31eaf485c0920a2d68b |