iter-model uses a method approach instead of individual functions to work with iterable objects.
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-1.0.0.tar.gz
(5.1 kB
view hashes)
Built Distribution
Close
Hashes for iter_model-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d43f121c877dc45073ab72483a5c2e0a035028ce5b61442c140cca69370f2442 |
|
MD5 | 94dd7c9d430f3bc626d58d76dc638887 |
|
BLAKE2b-256 | c532daf4f91fd6624d46fed8d2574d6a7dca01bd5e03400976827eec2469559f |