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.13.tar.gz
(3.4 kB
view hashes)
Built Distribution
Close
Hashes for iterlite-0.1.13-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4e6a8f80dbf7f75a967c0b8e69c995aa65fa74b4d7c7eae5c24058a4d57d797a |
|
MD5 | 0037e5f13134ef2bdb4a89379df980ac |
|
BLAKE2b-256 | ee97296caed25f275d779063ebdb501f7745a3214f295875b68d31a0846e3b79 |