Skip to content

angelcaru/pyabstractdatatype

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Abstract Data Types for Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages