Partial function application with '...'
Partial argument application using
An enhanced version of
allows partially applying positional arguments from both the left and right
sides of the argument list.
... (the Ellipsis object) as a placeholder in the argument list for
the arguments that are not yet supplied. The object returned from
also supports being called with
... for further partial application.
partial as a function decorator (
@partial) to make a function
automatically support partial argument application with
As a drop-in replacement for
>>> from partiell import partial >>> from operator import mul, truediv >>> double = partial(mul, 2) # same as functools.partial() >>> double(5) 10 >>> halve = partial(truediv, ..., 2) # functools.partial() cannot do this >>> halve(3) 1.5
As a function decorator to enable smoother partial function application:
>>> @partial ... def f(x, y, z): ... return x * 100 + y * 10 + z
f() can now be called with
... for partial function application:
>>> g = f(1, ...) # Supply first argument only (x) >>> g(2, 3) # Supply the two remaining arguments (y, z) 123
Functions derived from
f() automatically support
>>> h = g(2, ...) # Supply g's first argument (y) >>> h(3) # Supply the final argument (z) 123
... placeholder also allows supplying arguments right-to-left:
>>> i = f(..., 3) # Supply last argument only (z) >>> i(1, 2) # Supply the remaining arguments (x, y) 123
We can even supply arguments from both ends simultaneously:
>>> j = f(1, ..., 3) # Supply first and last argument (x, z) >>> j(2) # Supply the remaining argument (y) 123
... as a placeholder for future function arguments allows for a
"functional light" programming style that is somewhere between the verbosity
of invoking partial() explicitly and the implicit currying provided by e.g.
@curry decorator in PyMonad.
Run the following to install:
$ pip install partiell
To work on partiell, clone this repo, and run the following (in a virtualenv) to get everything you need to develop and run tests:
$ pip install -e .[dev]
Alternatively, if you are using Nix, simply use the bundled
shell.nix to get
a development environment:
run_tests.sh script to run all tests:
Main development happens at https://github.com/jherland/partiell/. Post issues and PRs there.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size partiell-0.0.1-py3-none-any.whl (8.8 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size partiell-0.0.1.tar.gz (11.8 kB)||File type Source||Python version None||Upload date||Hashes View|