Skip to main content

No project description provided

Project description

deferpy

Deferred function calls are pushed onto a stack. When a function returns, its deferred calls are executed in last-in-first-out order.

The Go Blog has a good explanation of the behavior of defer. This package attempts to recreate the behavior as closely as possible.

Installation

 $ pip install deferpy

Usage

Check out the tests to see more examples.

>>> from deferpy import defer
>>> @defer()
... def function(a, b, c):
...     function.defer(print, a)
...     function.defer(print, b)
...     function.defer(print, c)
...     return a + b + c
... 
>>> print(function(1, 2, 3))
3
2
1
6
>>> @defer()
... def func():
...     for i in range(10):
...         func.defer(print, i)
... 
>>> func()
9
8
7
6
5
4
3
2
1
0

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

deferpy-1.0.1.linux-x86_64.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

deferpy-1.0.1-py3-none-any.whl (3.1 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