19 lines
563 B
Python
19 lines
563 B
Python
from enum import Enum
|
|
from typing import Optional
|
|
|
|
class Result:
|
|
def __init__(self,
|
|
success: bool,
|
|
reason: str,
|
|
value: Optional[any] = None) -> None:
|
|
self.success = success
|
|
self.reason = reason
|
|
self.value = value
|
|
|
|
@classmethod
|
|
def succeed(cls, value: any, reason: str = 'Ok') -> 'Result':
|
|
return cls(True, reason, value=value)
|
|
|
|
@classmethod
|
|
def fail(cls, reason: str, value: Optional[any] = None) -> 'Result':
|
|
return cls(False, reason, value=value)
|