No project description provided
Project description
dataclass-applicative
--- treating dataclasses like containers
This package provides functions for manipulating dataclasses as containers.
Documentation
The documentation is hosted on ReadTheDocs, and the source code for that documentation is available here.
Quick start
Given a dataclass,
>>> from dataclasses import dataclass
>>> from dataclass_applicative import amap, fmap, gather, pure, names, values
>>> @dataclass
... class F:
... x: object
... y: object
... z: object
we can list its fields;
>>> list(names(F))
['x', 'y', 'z']
list its values;
>>> list(values(F(1, 2, 3)))
[1, 2, 3]
default-construct new instances;
>>> pure(F, 1)
F(x=1, y=1, z=1)
apply a function to those values;
>>> fmap(str, F(1, 2, 3))
F(x='1', y='2', z='3')
or apply functions stored in one object to values stored in another;
>>> amap(F(str, lambda _: 999, lambda z: z + 1), F(1, 2, 3))
F(x='1', y=999, z=4)
and gather all attributes from many instances into tuples in a new object:
>>> gather(F(1, 2, 3), F(10, 11, 12), F(3, 2, 1), F(0, 0, 0))
F(x=(1, 10, 3, 0), y=(2, 11, 2, 0), z=(3, 12, 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 dataclass-applicative-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0923029a4d59b46bd8e10dbc964434b13038d62a937a0fb73a6cb86c9cb733df |
|
MD5 | ea6ed41cae99e0ce625ba4df52d0c931 |
|
BLAKE2b-256 | f73f87a4e667daa293594c54513550aa3362125118d9adea94d5c033d720c50b |
Close
Hashes for dataclass_applicative-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12db21484acc0a06c77279da5a0d9a34488af560c0b3f13b7b0b23782290569a |
|
MD5 | 7deb6686bd3d7977f1dfb037d37979a5 |
|
BLAKE2b-256 | 79a4b7ba35575197857f4f7a6898735a668b45967baa13df8ee68dd23a0a2792 |