rust like iterators for python
Project description
Better iterators for python (all typed)
Examples
1. Simple
## create iterator for even integers squared
even_integers = Iter(range(100)) \
.filter(lambda x: x % 2 == 0) \
.map(lambda x: x ** 2)
## to evaluate into a list use
my_list = even_integers.to_list()
## The smart list will allow the usage of iterator notation again by
times2_iter = my_list.iter() \
.map(lambda x: x * 2)
2. Usage with inbuilt types
Unfortunately python doesn't support extensions to in-built types. Thus we can only create wrappers to allow the functionality
To use it with in-built lists while keeping the list functionality use
# Instead of
my_list = list([5, 4, 3, 2, 1])
# Use the following to be Iter compatible
my_list = SList([5, 4, 3, 2, 1])
3. Sized iterators
When using stored data where we know the size of the collection (see collection)
Then we can wrap them slightly differently to have a few more functions in a nice format
# store the list as a collection iterable (aka sized)
my_collection = IterCollection(list(10))
# Then we can know the length of the collection without having to traverse the iterator
l = my_collection.len() # will call the __len__ of the wrapped class. In this case list
# We can also reverse the collection
rev = my_collection.reversed() # returns an iterator not a collection
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
iterlite-0.1.10.tar.gz
(3.3 kB
view hashes)
Built Distribution
Close
Hashes for iterlite-0.1.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce6094bc6ec7aa1486b004a9292803e71802681eefa862d32f39ec1d26d9ec39 |
|
MD5 | 91cb5f3339e612ec8f349ab5372e99c1 |
|
BLAKE2b-256 | bb0c6c4991de845eeda5e83adccf47862214744d0af67b42a4ff2166451f9d74 |