Skip to main content

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


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.2.2.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

iterlite-0.2.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file iterlite-0.2.2.tar.gz.

File metadata

  • Download URL: iterlite-0.2.2.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for iterlite-0.2.2.tar.gz
Algorithm Hash digest
SHA256 ef3de05365a2bb1e2dfcc34771d9e9b12cd8cd381edac456ee0e98f736ec716e
MD5 278dd8a09109702bf6adfefcc8139fef
BLAKE2b-256 9f647a2df101fd71118426a9e0f205eb00dff1b5d78e9fd9ad2303d85c4ae927

See more details on using hashes here.

File details

Details for the file iterlite-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: iterlite-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for iterlite-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9c96f93b4a72f1516e81effc706c713a3ae6dd831d4447065c4cb157f527dee7
MD5 076bfe0d8df5346c1af12f1bc558acb2
BLAKE2b-256 01f087835eecd96de24d6dbc0ff1652ed2eab7c07808163b0f7761fdddf04e72

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page