Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dataclass-applicative-0.1.0.tar.gz (4.2 kB view hashes)

Uploaded Source

Built Distribution

dataclass_applicative-0.1.0-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page