MAZ
A functional programming package.
Install
pip install maz
Main usage
Function composition
You can use maz to compose function calls such that they call one another in a series.
NOTE: functions are called from right to left.
>>> import maz
>>> succ = lambda x: x+1
>>> add_three = maz.compose(succ,succ,succ)
>>> add_three(4)
>>> 7
Partial function
When you want to fix a parameter in a function, you could just use the functools.partial. However, that doesn't support fixing a positional argument on a specific index, which are quite common later on when you want to build complex compositions. Here you can use the maz.partialpos instead
>>> import maz
>>> def add(x,y): return x+y
>>> add_two = maz.partialpos(add, {1:2}) # fixing argument for index 1 to 2 (y=2)
>>> add_two(3)
>>> 5
Complex compositions
To support more complex compositions we've added some special functions such as
import maz
import operator
import itertools
# "invoke" function - a function calling other functions
def add(x,y):
return x+y
maz.invoke(add, [1,2]) # >>> 3
maz.invoke_star(add, 1, 2) # >>> 3
# "fnmap" function will compute all input functions in a
# series with same given arguments
fn = maz.fnmap(add, add, add)
fn(1,2) # >>> [3, 3, 3]
# "ifttt" returns a new function that checks the input somehow
# then does something depending on the result from the check
fn = maz.ifttt(
# if x is greater than 3,
lambda x: x > 3,
# then subtract 1 from x
lambda x: x - 1,
# else add 1 to x
lambda x: x + 1
)
fn(3) # >>> 4
fn(4) # >>> 3
# "starfilter" just as itertools.starmap but a filter instead
# Example, filter tuples who's sum is greater than 4
next(
maz.starfilter(
maz.compose(
lambda i: i > 4,
add
),
itertools.product(range(3), range(3,6))
)
) # >>> (0,5)
# "constant" returns a function which, no matter the argument, returns a constant value.
cnst_fn = maz.constant(True)
cnst_fn() # >>> True
cnst_fn(cnst_fn()) # >>> True
Other functions
We've added a tools module to provide functions that are in the middle of being simple enough to just write it yourself but tideous enough to not do it.
from maz.tools import reverse_otm_dict
# Reversing a one-to-many relationship map
d = reverse_otm_dict({
"a": [1,2,3],
"b": [1,2,4],
"c": [4,5]
})
# >>> d
# {
# 1: frozenset({"a", "b"}),
# 2: frozenset({"a", "b"}),
# 3: frozenset({"a"}),
# 4: frozenset({"b", "c"}),
# 5: frozenset({"c"}),
# }
Metadata
Release files for maz 0.0.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| maz-0.0.12.tar.gz | 6.8 kB | Without provenance | Details for maz-0.0.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| maz-0.0.12-py3-none-any.whl | Python 3 | none | any | Details for maz-0.0.12-py3-none-any.whl |
Total release size: 14.6 kB
Release files / maz-0.0.12.tar.gz
| Download URL | maz-0.0.12.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3aefd6fa0b6168288c5450a495adbf6f5ec336befbe447801bd2ba9882427df2
|
|
BLAKE2b-256 checksum How to use checksums |
44d18eedd2f26566582cd80d7324105e0530b4696491db8f9af85c2a5b88886f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / maz-0.0.12-py3-none-any.whl
| Download URL | maz-0.0.12-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
20f5f9d8dfd644dd8559cc1cafd9102c30acd63e17cc5307252199be822d2d3a
|
|
BLAKE2b-256 checksum How to use checksums |
4e16ab3d4e62369f66622764d6a9878d59f43a04ea7ce105543e635003dffc19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Security for maz 0.0.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.