Oct 20, 2022
Following up on my previous comment, here's the last two as dataclasses:
@dataclass(frozen=True)
class Just:
value: Any def __or__(self, f):
return Just(f(self.value))
and
@dataclass(frozen=True)
class Nothing:
value = None def __or__(self):
return self
No boring bits!
(And yes, I did try it out, and a dataclass
with no fields at all is completely OK, which is good, but not totally surprising because it is the right choice.)