Skip to content
New issue

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

feature request: Add an export method #116

Open
showell opened this issue Mar 26, 2023 · 1 comment
Open

feature request: Add an export method #116

showell opened this issue Mar 26, 2023 · 1 comment

Comments

@showell
Copy link

showell commented Mar 26, 2023

Hello, I recently wrote the following code for a project I am working on:

def export(expr, *, f_and, f_or, f_not, f_symbol):
    def f(expr):
        if type(expr) == boolean.boolean.OR:
            return f_or([f(arg) for arg in expr.args])
        elif type(expr) == boolean.boolean.AND:
            return f_and([f(arg) for arg in expr.args])
        elif type(expr) == boolean.boolean.NOT:
            return f_not([f(arg) for arg in expr.args])
        elif type(expr) == boolean.boolean.Symbol:
            return f_symbol(expr.obj)
        else:
            assert False
    return f(expr)

https://github.com/showell/boolean-py-export-example includes that code, and I describe my use case in a little more detail.

The quick summary is that once boolean.py has done the heavy lifting of simplifying my boolean expression, I want to export the objects into my own data structure. (I understand that the docs suggest to do this by subclassing Symbol, NOT, AND and OR functions, but this feels unnecessarily awkward to me.)

The urgency on my end is pretty low, as I am only using this in a standalone project for now, but I suspect other folks might benefit from the code. If this seems like a worthwhile extension, I can probably submit a PR.

@showell
Copy link
Author

showell commented Mar 26, 2023

(I suppose you could also re-brand my "export" function as a "visit" function. As always, apologies if I have overlooked anything in the docs.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant