Skip to main content

A Functor library for Python

Project description

pyfunctor is a Python Functor library that provides classes implementing lazy evaluation, pipeline operators and block syntax.

An example of usages is following:

>>> from pyfunctor.functor import *
>>> f = (Functor(range(10)) >> c_(map)(lambda x: x * 2)
...      >> c_(filter)(lambda x: x < 7)
...      >> c_(sorted).key(lambda x: -x))
>>> run(f)  # lazy evaluation
[6, 4, 2, 0]

The ‘Functor’ class packs a value into a context. The pipeline operator ‘>>’ composes functions, but it is not calculated until ‘run’ function is applied to the Functor object.

Furthermore, Functor object will work together with the ‘with’ statement. The object is only once evaluated after the with-block is done.

>>> with Functor(range(10)) as box:
...     @c_(map)
...     def f(x):
...         y = x % 3
...         z = x + y
...         return x + y + z
...
...     @c_(sorted, keyword='key')
...     def g(x):
...         return (x % 7, x % 3, x)
>>> box.value
[0, 14, 8, 16, 10, 18, 4, 12, 6, 20]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pyfunctor, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size pyfunctor-0.1.2.tar.gz (4.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page