mwchase icon

Sample sum_type code

mwchase | PRO | 06/05/18 09:35:11 PM UTC | 0 ⭐ | 824 👁️ | Never ⏰ | []
Python |

390 B

|

None

|

0 👍

/

0 👎

R = typing.TypeVar('R')
E = typing.TypeVar('E')
 
@sum_type
class Result(typing.Generic[R, E]):
    """Experimental generic ADT."""
 
    __slots__ = ()
 
    Ok: Ctor[R]
    Err: Ctor[E]
 
my_result: Result[int, str] = Result.Ok(10)
 
@sum_type
class ConcreteResult:
 
    __slots__ = ()
 
    Ok: Ctor[int]
    Err: Ctor[str]
 
my_concrete_result: ConcreteResult = ConcreteResult.Ok(10)

Comments