Skip to main content

Iterator class for functional programming

Project description

f_it: Functional Iterator

https://img.shields.io/pypi/pyversions/f_it.svg https://img.shields.io/pypi/v/f_it.svg https://img.shields.io/travis/clbarnes/f_it.svg Documentation Status https://img.shields.io/badge/code%20style-black-000000.svg

Iterator class for functional programming in python

Features

  • A single wrapper class exposing chain-able methods for lazily transforming iterators

  • Wraps functions from functools, itertools, and some extras

  • Optionally has a length, which is calculated for subsequent operations if possible

Note that this package is for convenience/ interface comfort purposes and does not provide the guarantees of a true functional language.

Install

pip install f_it

Usage

from f_it import FIt

it = FIt(range(10))
transformed = it.map(  # cube elements
    lambda x: x**3
).filter(  # drop even elements
    lambda x: x % 2
).cycle(  # repeat the whole iterator 3 times
    3
).islice(  # take some elements from the middle
    5, 10
).chain(  # add 0-4 to the end
    range(5)
).chunk(  # separate into 2-length chunks
    2
)

# nothing has been evaluated yet!

# evaluate operations, reading into a list
# if tqdm is available, show progress bar
as_list = transformed.progress().to(list)

History

0.1.0 (2019-08-21)

  • First release on PyPI.

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

f_it-0.2.1.tar.gz (16.2 kB view hashes)

Uploaded Source

Built Distribution

f_it-0.2.1-py2.py3-none-any.whl (8.1 kB view hashes)

Uploaded Python 2 Python 3

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