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

Return function without call #28

Open
fliepeltje opened this issue May 23, 2019 · 1 comment
Open

Return function without call #28

fliepeltje opened this issue May 23, 2019 · 1 comment

Comments

@fliepeltje
Copy link

The current behavior is that if an action is a function it by default gets called; I have some scenarios where this is undesireable. For instance, I might want to decide how to process data based on an enum and bind my processing function to that enum. I would want to know which function to use, but not yet call it and certainly not with the enum value. Or alternatively I might want to interpret and pattern match on dataset A and based on that determine how to process an entirely different dataset B.
Example:

fn = match(exp,
{"field": "some_value"}, fn_a,
{"field": "some_other_value"}, fn_b,
)
fn("some_string")

The above would fail because it would call the function with a dict while the functions expects a string.

currently the above is possible with the following hack:

fn = match(exp,
{"field" : "some_value"}, lambda x: fn_a,
{"field" : "some_other_value"}, lambda x: fn_b
)

however, this drastically diminishes readability.

I propose one of the following 2 solutions:

  1. Check whether the action is a lambda function and only call it if this is the case
  2. Add a named parameter to match that determines whether the given action is called or not.
@adamlwgriffiths
Copy link

Sounds like the better option here is to make a new version of match that suits your needs.
Take every second parameter and wrap it in a lambda and then pass that to match.

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

2 participants