Skip to main content

Replace common looping boilerplate with pretty method chaining.

Project description

tests

Welcome to loop

Replace common looping boilerplate with pretty method chaining.

Installation

pip install loop-python

Documentation

Visit the documentation site.

Example

Loop over range(20), apply the fibo() function and then, on top of it, apply the fizzbuzz() function, finally, apply print():

from loop import loop_over


def fizzbuzz(x):
    rules = {3: 'fizz', 5: 'buzz'}.items()
    res = ''.join(word for div, word in rules if x%div == 0)
    return res if res else x


def fibo(x):
    a, b = 1, 1
    for _ in range(1, x):
        a, b = b, a + b
    return b


loop_over(range(20)).map(fibo).map(fizzbuzz).map(print).exhaust()

Will produce the following output:

1
1
2
fizz
buzz
8
13
fizz
34
buzz
89
fizz
233
377
buzz
fizz
1597
2584
4181
fizzbuzz

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

loop-python-0.4.0.tar.gz (16.7 kB view hashes)

Uploaded Source

Built Distribution

loop_python-0.4.0-py3-none-any.whl (9.5 kB view hashes)

Uploaded 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