Last active
August 17, 2024 12:10
-
-
Save nerodono/18595b7bc946a986f97b426c0edf7d50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dataclasses as dtc | |
@dtc.dataclass | |
class Ok: | |
ok: "Nigger" | |
@dtc.dataclass | |
class Err: | |
err: "Gay" | |
def then(lhs, rhs): | |
def impl(req, next): | |
return lhs(req, lambda x: rhs(x, next)) | |
return impl | |
def bind(lhs): | |
def impl(req, next): | |
if isinstance(req, Ok): | |
return lhs(req.ok, next) | |
return next(req) | |
return impl | |
def identity(x): | |
return x | |
def ratio(req, next): | |
if req == 0.0: | |
return next(Err("division by zero")) | |
return next(Ok(1.0 / req)) | |
def apply(h, f): | |
return lambda x: h(x, f) | |
num_identity = apply(then(ratio, bind(ratio)), identity) | |
print(num_identity(10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mypy: Success: no issues found in 1 source file