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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for deferpy-1.0.1.linux-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b787342bd91756998944a1f45c6b7381db55d9b3d0d1643edea92371d8fd25ed |
|
MD5 | 8e4ff2991a89f4b841c03f18f82052d8 |
|
BLAKE2b-256 | 3dbb3b1dc7a58a82fc88021ac08fcd40ef04cbc3e140e0c1e02642ef32b548b0 |