2025-01-19
I try to implement a Python version of the Result<T, E> sum type in rust which can be used with match/case pattern matching.
The pattern matching with sub-patterns like case Err(e) could be implemented in Python with the __match_args__ dunder attribute. This is how Result[T, E], OK() and Err() defined:
import typing T = typing.TypeVar('T') E = typing.TypeVar('E') class Result[T, E]: __match_args__ = ('_val',) def __init__(self, val): self._val = val class Ok[T](Result[T, .
Continue reading