Abstract Data Types for Python
Project description
PyADT
A simple library that adds ADTs to Python.
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
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for pyabstractdatatype-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7e5d4d928d4b088990c0a40790c7b7a08191b5aab0cfa433c6855ae7d6f583d |
|
MD5 | 86eac49c03c0ef1f58141b251097c6f3 |
|
BLAKE2b-256 | 2a16edb8629cc9a1db9800ae7cc02146cbac0ec900c00c608d081710be5499b9 |