We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I always want to write something like Haskell in Python
with Multimethod() as fib: fib[1] = 1 fib[2] = 2 fib[int] = lambda n: fib(n-1) + fib(n-2)
and this can be done by leveraging the pampy package and some simple clasees
class Matcher: def __init__(self): self.pattern = [] def __setitem__(self, pat, method): self.pattern.append(pat) self.pattern.append(method) def __call__(self, *x): if len(x)==1: x = x[0] return match(x, *self.pattern)
class Multimethod: def __init__(self, *sig): pass def __enter__(self): return Matcher() def __exit__(self, *args): pass
Would it be good to have something like this inside the package?
The text was updated successfully, but these errors were encountered:
I think this is interesting, as it lets you dynamically add new patterns dynamically - something I find myself wanting.
convert = Matcher() convert[int] = lambda x: 'integer' convert[str] = lambda x: 'string' # etc
It would be even better if we had proper anonymous functions.
Sorry, something went wrong.
No branches or pull requests
I always want to write something like Haskell in Python
and this can be done by leveraging the pampy package and some simple clasees
Would it be good to have something like this inside the package?
The text was updated successfully, but these errors were encountered: