A small library to provide multi-methods. All functions are in the dialogue.multi_method package.
To create a multi-method, create a dispatch function, that takes the arguments and returns a hashable value, that is used to dispatch on. Use the @multi function annotation to annotate the function.
For each value of the dispatch function that you want to be handled differently, create a method with that dispatch value.
You can define a method with no dispatch value, that becomes the default method if no other method is defined for a dispatch value.
An example:
@multi def number(x): return x @method(number, 1) def number_one(x): return 'one' @method(number) def number_other(x): return "not one, but "+ str(c) assert number(1) == 'one' assert number(0) == 'not one, but 0'
The dispatch function is available, e.g. for testing:
assert dispatch_fn(number)('x') == 'x'
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file dialogue.multi-method-0.0.5.tar.gz.
File metadata
- Download URL: dialogue.multi-method-0.0.5.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.9.1 pkginfo/1.4.1 requests/2.18.3 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.15.0 CPython/3.6.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f83adb2802c327514d1ad3fdb32cfefcc0818ba1e6281a35b595254caa21473
|
|
| MD5 |
c8b9d3b0022f990b8778776d7dc86112
|
|
| BLAKE2b-256 |
8d591dc742320c5dc21abac38553deb11b34482e2c7779dbb30ab05dc5de8167
|