Skip to main content

Abstract Data Types for Python

Project description

PyAbstractDataType

A simple library that adds ADTs to Python.

Source Code

Documentation

Basic usage:

from adt import adt

@adt
class MyADT:
    Variant1: (int, int)
    Variant2: (int)
    Variant3: (str, str, list[float])

Supports match statement!

obj1 = MyADT.Variant1(2, 2)
obj2 = MyADT.Variant3("hi", "foo", [2.3, 5.6, 3.1415])

objs = obj1, obj2

for obj in objs:
    match obj1:
        case MyADT.Variant1(a, b):
            print(f"Found you! {a}, {b}")
        case MyADT.Variant2(x):
            print(":(")
        case _:
            raise ValueError("wtf")

Output:

Found you! 2, 2
Traceback (most recent call last):
...
ValueError: wtf

Examples

See example.py.

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

pyabstractdatatype-0.0.2.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

pyabstractdatatype-0.0.2-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file pyabstractdatatype-0.0.2.tar.gz.

File metadata

  • Download URL: pyabstractdatatype-0.0.2.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for pyabstractdatatype-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b74f2b567c194fbd07892919e89e109f11d7495eb0457140bb721b306dece587
MD5 69c9904176ed862e0cd9873527d98b38
BLAKE2b-256 c18254b66c3dfe7c25a91e38a1c5012cee10b212597e5d77f2353b21189122c4

See more details on using hashes here.

File details

Details for the file pyabstractdatatype-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pyabstractdatatype-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d46de2f30a8d3840e8733277eaad34908613b1f30eb1c015e1f6c603c917ebf6
MD5 d9fc01fe95a891743bbf1b3ac34c77f3
BLAKE2b-256 ac3e2d535feb04bfc2d0bcd28fc1b7f9abeccfbc9617fe0ba743c0880a1344bf

See more details on using hashes here.

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