Skip to main content

Rust-style iterators for Python!

Project description

Chemical

Rust-Style Iterators in Python!

Compose iterator sequences like chemical compounds!

Quickstart

>>> from chemical import it

>>> my_iter = it([1, 2, 3])
>>> my_iter.next()
1
>>> my_iter.next()
2
>>> my_iter.next()
3

>>> it('abc').map(lambda x: x.upper()).collect(str)
'ABC'

>>> it('abc').inspect(print).go()
a
b
c

>>> for num in it(range(100)).skip(10).take(10).rev().step_by(4):
...     print(num)
19
15
11

>>> # Same as above but written as an expression:
>>> it(range(100)).skip(10).take(10).rev().step_by(4).for_each(print).go()
19
15
11

>>> # Large Chemical compositions can span multiple lines using parentheses:
>>> (it(range(100)
...      .skip(10)
...      .take(10)
...      .rev()
...      .step_by(4)
...      .for_each(print)
...      .go()
... )
19
15
11

About

Chemical takes heavy inspiration from the iterators that can be found in the Rust Programming Language. Chemical provides composable, customizable, and powerful iterators that can be combined, chained, aggregated, and so much more.

Although Python has very powerful iterators already, Chemical provides a way to programatically compose them to create highly compact but comprehendible behaviors.

You can even add your own "traits" to the it class at runtime and they will be available for use anywhere in your program! This allows you to create custom functionality without having to use your own type derived from it.

Installation

$ pip install chemical

Chemical has been tested on:

  • Windows
  • MacOS
  • Linux
  • Python 3.6
  • Python 3.7
  • Python 3.8

To run the unit tests:

$ git clone https://github.com/Pebaz/Chemical
$ cd Chemical
$ pip install -r requirements.txt
$ pytest

Documentation

You can view the generated documentation here.

You can also look at the source code for more insight on how you can extend it to have more iterators and aggregators specific to your own application.

The unit tests also provide an abundant amount of examples as they cover every iterator/aggregator in Chemical.

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

chemical-1.0.1.tar.gz (11.6 kB view details)

Uploaded Source

File details

Details for the file chemical-1.0.1.tar.gz.

File metadata

  • Download URL: chemical-1.0.1.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for chemical-1.0.1.tar.gz
Algorithm Hash digest
SHA256 add70a5dbb3b28d7c88bba7d468ced7b07b3461ece351cfbce19fa033042536f
MD5 d5b7abda0706ffc23e3a416448c58d1d
BLAKE2b-256 4ff36f678ae297bfe30cf4433ae56551e6605e83b471631c45ff0a180459b27d

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 Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page