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

on_error Functionality #65

Closed
EntilZha opened this issue Apr 4, 2016 · 1 comment
Closed

on_error Functionality #65

EntilZha opened this issue Apr 4, 2016 · 1 comment
Assignees
Milestone

Comments

@EntilZha
Copy link
Owner

EntilZha commented Apr 4, 2016

The functionality from https://github.com/jagill/python-chainz#errors would be useful for certain use cases. Wrapping this into Lineage seems like a fairly clean way to accomplish this.

On a side note, this might be a good time to look at making the exceptions raised from evaluating an incorrect user function in a PyFunctional pipeline cleaner. Currently, there is quite a bit of noise when its is very unlikely the core issue is coming from PyFunctional.

@EntilZha EntilZha self-assigned this Apr 4, 2016
@EntilZha EntilZha added this to the 1.0.0 milestone Apr 4, 2016
@EntilZha EntilZha changed the title on_error Functionality on_error Functionality Apr 4, 2016
@EntilZha EntilZha modified the milestones: 0.7.0, 1.0.0 May 6, 2016
@EntilZha
Copy link
Owner Author

EntilZha commented May 7, 2016

Gave a good shot at implementing this and don't think that the changes to make it happen would be worth it.

Consider this code block:

def f(x):
    if x == 1:
        raise ValueError("Not 1!")
    return x * 2
seq.range(4).map(f)

In order to handle this, its not enough to wrap the code that executes the sequence, it will still error out. In order to catch that exception you either need to catch it where next is called, wrap f when it is passed through to map, or use a yield statement like done here https://github.com/jagill/python-chainz/blob/master/chainz/chain.py#L52

The first one is obviously not an option since thats user code vs library code. There are two possible problematic implementations:

  1. You could wrap f then pass it through. The issue is that there would need to be checks on all methods that accept a function if on_error would work as expected. This is a lot of methods that would have to be changed to support this single one which I don't think adds much value (more on this later)
  2. The second one is clear how to do for map and other functions that operate at a single "level". For example, flat_map since tricky since the results have to get concatenated. The generalization is that implementing this would be method specific so quite a bit of work.

Lastly, I don't think it brings much value for all the effort needed. It would be much easier for user code to handle the exception explicitly. This could be easy to do using flat_map very easily. If there is an error output an empty list, otherwise a tuple of one element (yay monads). It would also be easy to do a map then filter.

I had hoped the implementation wouldn't require so much code change and would be easy, but wasn't to be. I am open to other ideas, but closing issue for now.

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

No branches or pull requests

1 participant